sql query for filtering Access database by date
-
Hi, I am trying to fill the gridview with the data from an Access table for a range of dates.
Dim cmd1 As String = "Select \* from " & inpTable & " Where mdateTime = '29/09/2011'" MsgBox("cmd= " & cmd1) Dim da As OleDbDataAdapter Try da = New OleDbDataAdapter(cmd1, myConnection) Catch ex As Exception ' Catch the error. MsgBox(ex.ToString) ' Show friendly error message. End Try Try Dim table As New DataTable da.Fill(table) DataGridView1.DataSource = table Catch ex As Exception MsgBox(ex.ToString) End Try myConnection.Close()
Command as it appears in the MsgBox Select * from rawClimateData Where mdateTime > 30/09/2011 10:45:00 AM The query works if I am not filtering the data base; however, with filter I get the syntax error "missing operator". Any suggestion??
-
Hi, I am trying to fill the gridview with the data from an Access table for a range of dates.
Dim cmd1 As String = "Select \* from " & inpTable & " Where mdateTime = '29/09/2011'" MsgBox("cmd= " & cmd1) Dim da As OleDbDataAdapter Try da = New OleDbDataAdapter(cmd1, myConnection) Catch ex As Exception ' Catch the error. MsgBox(ex.ToString) ' Show friendly error message. End Try Try Dim table As New DataTable da.Fill(table) DataGridView1.DataSource = table Catch ex As Exception MsgBox(ex.ToString) End Try myConnection.Close()
Command as it appears in the MsgBox Select * from rawClimateData Where mdateTime > 30/09/2011 10:45:00 AM The query works if I am not filtering the data base; however, with filter I get the syntax error "missing operator". Any suggestion??
-
Hi, I am trying to fill the gridview with the data from an Access table for a range of dates.
Dim cmd1 As String = "Select \* from " & inpTable & " Where mdateTime = '29/09/2011'" MsgBox("cmd= " & cmd1) Dim da As OleDbDataAdapter Try da = New OleDbDataAdapter(cmd1, myConnection) Catch ex As Exception ' Catch the error. MsgBox(ex.ToString) ' Show friendly error message. End Try Try Dim table As New DataTable da.Fill(table) DataGridView1.DataSource = table Catch ex As Exception MsgBox(ex.ToString) End Try myConnection.Close()
Command as it appears in the MsgBox Select * from rawClimateData Where mdateTime > 30/09/2011 10:45:00 AM The query works if I am not filtering the data base; however, with filter I get the syntax error "missing operator". Any suggestion??
Rewrite this as a parameterized query and you won't have to worry about what "format" the datetime objects are in. Just Google for ".NET Sql parameterized query" and you'll find tons of exampels.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hi, I am trying to fill the gridview with the data from an Access table for a range of dates.
Dim cmd1 As String = "Select \* from " & inpTable & " Where mdateTime = '29/09/2011'" MsgBox("cmd= " & cmd1) Dim da As OleDbDataAdapter Try da = New OleDbDataAdapter(cmd1, myConnection) Catch ex As Exception ' Catch the error. MsgBox(ex.ToString) ' Show friendly error message. End Try Try Dim table As New DataTable da.Fill(table) DataGridView1.DataSource = table Catch ex As Exception MsgBox(ex.ToString) End Try myConnection.Close()
Command as it appears in the MsgBox Select * from rawClimateData Where mdateTime > 30/09/2011 10:45:00 AM The query works if I am not filtering the data base; however, with filter I get the syntax error "missing operator". Any suggestion??