Request for Date wise search Project
Plz make a coding for searching the data between 2 dates from MSAccess data by VB.NET.
Thanks.
OLeDB
to access OLeDB
libraries .
Imports System.Data.OleDb
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\peopledb.accdb") Dim cmd As OleDbCommand Dim da As OleDbDataAdapter Dim dt As DataTable Dim sql As String Dim maxrow As Integer
Private Sub Auto_Save(sql As String) Try con.Open() cmd = New OleDbCommand With cmd .Connection = con .CommandText = sql .ExecuteNonQuery() End With Catch ex As Exception MsgBox(ex.Message) Finally con.Close() End Try End Sub
Private Sub loaddtg(ByVal sql As String, ByVal dtg As DataGridView) Try con.Open() cmd = New OleDbCommand da = New OleDbDataAdapter dt = New DataTable With cmd .Connection = con .CommandText = sql End With da.SelectCommand = cmd da.Fill(dt) dtg.DataSource = dt Catch ex As Exception MsgBox(ex.Message) Finally con.Close() da.Dispose() End Try End Sub
Private Function numrows(sql) Try con.Open() cmd = New OleDbCommand da = New OleDbDataAdapter dt = New DataTable With cmd .Connection = con .CommandText = sql End With da.SelectCommand = cmd da.Fill(dt) maxrow = dt.Rows.Count Catch ex As Exception MsgBox(ex.Message) Finally con.Close() da.Dispose() End Try Return maxrow End Function
sql = "SELECT * FROM tblperson" loaddtg(sql, DataGridView1)
Private Sub DataGridView1_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit maxrow = DataGridView1.RowCount - 1 DataGridView1.Rows(DataGridView1.RowCount - 1).Cells(0).Value = maxrow For i As Integer = 0 To DataGridView1.RowCount - 2 With DataGridView1.Rows(i) sql = "SELECT * FROM tblperson WHERE ID=" & .Cells(0).Value maxrow = numrows(sql) If maxrow > 0 Then sql = "UPDATE tblperson SET Fname='" & .Cells(1).Value & "',Lname='" & .Cells(2).Value & "',Address='" & .Cells(2).Value & "' WHERE ID=" & .Cells(0).FormattedValue Auto_Save(sql) Else sql = "INSERT INTO tblperson (ID,Fname,Lname,Address) VALUES ('" & .Cells(0).Value & "','" & .Cells(1).Value & "','" & .Cells(2).Value & "','" & .Cells(3).Value & "')" Auto_Save(sql) End If End With Next End Sub