tsay
asked on
VB.NET Sql statement with datetime filter
Hey,
I want to select some rows from a SQL server database using vb.NET. The selection is based on a datetime field in Vb.NET (the datetime should be between two values which are colums in my sql table). I can't seem to find the correct format.
The statement should be something like
Select * from Table Where dotNetDate Between DateColumn1 and DateColumn2
If tried this in vb.net but it returns nothing...
sqlCmd = New SqlCommand("SELECT * FROM Table WHERE '" + pdatDate.ToString("d/MM/yy yy hh:mm:ss") + "' between FromDateTime and ToDateTime", objSQLConn)
Tnx for the help.
I want to select some rows from a SQL server database using vb.NET. The selection is based on a datetime field in Vb.NET (the datetime should be between two values which are colums in my sql table). I can't seem to find the correct format.
The statement should be something like
Select * from Table Where dotNetDate Between DateColumn1 and DateColumn2
If tried this in vb.net but it returns nothing...
sqlCmd = New SqlCommand("SELECT * FROM Table WHERE '" + pdatDate.ToString("d/MM/yy
Tnx for the help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this, vb seems to have this touch and go feelin when using the "+"
dim strdate as string =pdatDate.ToString("d/MM/y yyy hh:mm:ss")
sqlCmd = New SqlCommand("SELECT * FROM Table WHERE '" & strdate & "' between FromDateTime and ToDateTime", objSQLConn)
dim strdate as string =pdatDate.ToString("d/MM/y
sqlCmd = New SqlCommand("SELECT * FROM Table WHERE '" & strdate & "' between FromDateTime and ToDateTime", objSQLConn)
ASKER
Tnx angelIII.
try to compare it to each column: where pdatDate.ToString("d/MM/yy
Cheers!