Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string sql = "select * from   tblVehicle where CAST(floor( CAST( Vehentrytime AS FLOAT ) )AS DATETIME) = '?'";

In the question mark, I need to pass values of DateTime but my DateTime is in string and in short date time format.
In such case how can I pass the parameter of DateTime type?

My string holding the date is in format 11/4/2011 and i need to pass it inside '?' so how to do this?

With regards,
Bishnu Karki
Posted
Updated 2-Nov-11 23:04pm
v3
Comments
André Kraak 3-Nov-11 4:54am    
Edited question:
Added pre tags
Formatted text/code
Spelling/Grammar
Tejas Vaishnav 3-Nov-11 5:03am    
Please if you want to improve your question or you have any clarification then use Improve solution or Have a Question or Comment?... not post a solution
Dylan Morley 3-Nov-11 5:05am    
Edit: Move solution from OP into question

SQL
string sql = "select * from   tblVehicle where CAST(floor( CAST( Vehentrytime AS FLOAT ) )AS DATETIME) = 'yyyy-mm-dd'";


You need to pass date time with 'yyyy-mm-dd' format(of course in string format). This will serve your purpose.
 
Share this answer
 
Don't concatenate SQL strings like this, use a parameterized query

This article should explain everything

http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson06.aspx[^]
 
Share this answer
 
Comments
Dalek Dave 3-Nov-11 5:43am    
Good Link
Just pass it through either as a actual DateTime using a Parametrized query - in which case the problem goes away - or by converting the string into a DateTime first, then convert it back to an SQL compliant datetime string "yyyy-MM-dd hh:mm:ss".

Personally, I would go for the former - it';s a lot easier and more natural.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900