Selecting between SQL Server 2005 dates + vb.net code.

mike55

Well-known member
Joined
Mar 26, 2004
Messages
726
Location
Ireland
Hi all

I am trying to select between two dates in a sql table. This is the following statement that I am using:
Code:
sqlCmd.CommandText = "SELECT Count(ID) FROM SentMessages WHERE Org_ID = " & orgID _
                                            & " AND (Msg_Type = SMS OR Msg_Type = MO OR Msg_Type = WAP) AND (MessageDate BETWEEN " & Convert.todatetime(fromDate) & " AND " & convert.todatetime(toDate) & ")"
where todate and fromdate are both strings. I am getting the error message cannot convert from a char to a datetime.

Can anyone tell me how this should be done?

Mike55.
 
Did you try adding a .ToString to the Convert.todatetime(fromDate), like:

Convert.todatetime(fromDate).ToString ?

Oups, my bad, erase that! i didnt read it carefully
 
Back
Top