This is my first time posting after daniweb has helped me alot but I couldn't find a solution for this so I thought hey why not ask.
Basically I would like to have an sql statement which selects all the bookings from a table in microsoft access callled tblBookings where a certain date (selected by a datetimepicker) selected in vb.net.
The field the date is in access is bookingsdate and that is a shortdate aswell.
The problem is that even if the dates are the same the headers come up in the datagridview but no data.
This is my code:
Dim con As New OleDb.OleDbConnection Dim OleDBCon As System.Data.OleDb.OleDbConnection Dim ds As New DataSet Dim da As System.Data.OleDb.OleDbDataAdapter Dim sql As String Dim target2 As String Dim Target As String Dim Target3 As Date Dim target4 As Date Target = txtSearch.Text target2 = cmbFieldName.Text Target3 = dtpSearch.Value target4 = Format(Target3, "dd/MM/yyyy") If target2 = "" Then MsgBox("Please select a the type of information you are searching for.") Exit Sub End If con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = \DrivingSchool.mdb" MsgBox(target4) If target2 = "Student ID" Then sql = "SELECT * FROM tblBookings WHERE StudentID = " & Target Else If target2 = "Bookings ID" Then sql = "SELECT * FROM tblBookings WHERE BookingsID = " & Target Else If target2 = "Date" Then sql = "SELECT * FROM tblBookings WHERE LessonDate = " & target4 OleDBCon = New System.Data.OleDb.OleDbConnection(con.ConnectionString) 'sql is given a value by the if statements da = New System.Data.OleDb.OleDbDataAdapter(sql, OleDBCon) OleDBCon.Open() da.Fill(ds, "SearchedBookings") DataGridView1.DataSource = ds.Tables("SearchedBookings") End Sub
I hope someone can help me, if you need any more information just ask. Oh I am using visual studio 2008 if it makes any difference.