mike55 Posted April 13, 2006 Posted April 13, 2006 Hi all I am trying to select between two dates in a sql table. This is the following statement that I am using: 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. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted April 13, 2006 Administrators Posted April 13, 2006 Use a parametrised query, then the whole issue of string handling and differing formats goes away. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Puiu Posted April 14, 2006 Posted April 14, 2006 Did you try adding a .ToString to the Convert.todatetime(fromDate), like: Convert.todatetime(fromDate).ToString ? Oups, my bad, erase that! i didn't read it carefully Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.