Problem with between function with date timepicker
-
hello i am using SQL server 2005 as my back end now i want report of like from this date to this date...for that i wrote query like format of my date is dd/MMM/yyyy
If optn1.Checked = True Or optn3.Checked = True Then
sqlstr="select * from des_mast"
sqlstr = sqlstr & "where pickup_date between '" & Me.dtp1.Value & "' and '" & Me.dtp2.Value & "'"
End Ifbut while executing this query shows an error message like "incorrect syntax near the keyword 'between'" please suggest i cant get where the problem is thank you
-
hello i am using SQL server 2005 as my back end now i want report of like from this date to this date...for that i wrote query like format of my date is dd/MMM/yyyy
If optn1.Checked = True Or optn3.Checked = True Then
sqlstr="select * from des_mast"
sqlstr = sqlstr & "where pickup_date between '" & Me.dtp1.Value & "' and '" & Me.dtp2.Value & "'"
End Ifbut while executing this query shows an error message like "incorrect syntax near the keyword 'between'" please suggest i cant get where the problem is thank you
-
hello i am using SQL server 2005 as my back end now i want report of like from this date to this date...for that i wrote query like format of my date is dd/MMM/yyyy
If optn1.Checked = True Or optn3.Checked = True Then
sqlstr="select * from des_mast"
sqlstr = sqlstr & "where pickup_date between '" & Me.dtp1.Value & "' and '" & Me.dtp2.Value & "'"
End Ifbut while executing this query shows an error message like "incorrect syntax near the keyword 'between'" please suggest i cant get where the problem is thank you
Change this SQL statement to a parameterized query, then you won't have to worry about the format of the date values coming from the controls. It'll be handled for you and will also prevent some injection attacks in your code.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008