IvanHowarth
asked on
VB.net 1/SQL 2k: Nothing is returning from the DB using a WHERE clause with a date datatype.
I have a SQL 2k Table with a col of the smallDateTime dataType (MyDateCol). From my VB.net app, I want to fill my dataTable with all the records in that table that meet a date range. The dataAdapter has two parameters:
MyDataAdapter.SelectComman d.Paramete rs("@Start Date").Val ue = New Date(2007,1,1)
MyDataAdapter.SelectComman d.Paramete rs("@EndDa te").Value = New Date(2007,12,31)
My VB App:
MyDataAdapter.SelectComman d.CommandT ext = "SELECT MyCols FROM MyDataBase.dbo.MyTable WHERE (MyDateCol>= @StartDate) OR (MyDateCol<= @EndDate)"
My Sql Table
Value of MyDateCol = '2007-07-25 11:45:00'
Upon calling the fill method, nothing is returned. The above WHERE date clauses surely catch the Sql date value, but how can I get it to be recognised and thus returned?
MyDataAdapter.SelectComman
MyDataAdapter.SelectComman
My VB App:
MyDataAdapter.SelectComman
My Sql Table
Value of MyDateCol = '2007-07-25 11:45:00'
Upon calling the fill method, nothing is returned. The above WHERE date clauses surely catch the Sql date value, but how can I get it to be recognised and thus returned?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would add a time to it given that the value in your mydatecol does hold a real time. I have always used the shortdate version which defaults the time to 00:00.
ASKER
Following that idea. Thanks again Dale!
ASKER
Before I award you the points...
I can't get the records where MyDateCol = '2007-07-25 11:45:00' --i.e. today when
MyDataAdapter.SelectComman
MyDataAdapter.SelectComman
Only when I expand the range. Any ideas, or should I add a time to it e.g. 00:01 and 23:59 respectively?