Problem with selecting data between two dates
I would really appriciate it if someone could help me with the following. I have a Form with two DateTimePickers (dtpFrom & dtpTo) and a DataGridView. Iâm trying to pass the date from (dtpFrom) and date to (dtpTo) to my query to filter my data but get the following error: âMissing Operandâ. Below please find my code. Thanks.
Dim strCon As String
strCon = "Provider=VFPOLEDB.1;Data Source=D:\fm\;Collating Sequence=GENERAL"
Dim objCon As New OleDbConnection(strCon)
Dim strSelect As String
strSelect = "SELECT * FROM fuellings WHERE (td >= @FromDate) AND (td <= @ToDate)"
Dim SelectCommand As New OleDbCommand(strSelect, objCon)
Dim strFrom As String
Dim strTo As String
strFrom = dtpFrom.Text
strTo = dtpTo.Text
Try
objCon.Open()
SelectCommand.Parameters.AddWithValue("@FromDate", strFrom)
SelectCommand.Parameters.AddWithValue("@ToDate", strTo)
Dim objDA As New OleDbDataAdapter(strSelect, objCon)
Dim objDT As New Data.DataTable("fuellings")
objDA.Fill(objDT)
GridEX1.DataSource = objDT
Debug.WriteLine(objCon.State.ToString)
Catch ExceptionErr As Exception
MessageBox.Show(ExceptionErr.Message)
Finally
objCon.Close()
objCon.Dispose()
objCon = Nothing
End Try
Thanks
|