Click here to Skip to main content
15,941,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get this error in the following code line
"Implicit conversion from data type datetime to decimal is not allowed. Use the CONVERT function to run this query."
Can anybody help me to coorect this?? I need the correct format. :(


I tried in all these 3 ways, but nothing worked :( Please help

string cJoinD = DateTime.Now.ToShortDateString();
cmdupd.Parameters.Add(new SqlParameter("@JoinDate", SqlDbType.DateTime));
cmdupd.Parameters["@JoinDate"].Value = cJoinD;



cmdupd.Parameters.Add(new SqlParameter("@JoinDate", SqlDbType.DateTime));
cmdupd.Parameters["@JoinDate"].Value = DateTime.Today;



cmdupd.Parameters.Add(new SqlParameter("@JoinDate", SqlDbType.DateTime));
cmdupd.Parameters["@JoinDate"].Value = Convert.ToDateTime(dtpJoinDate.Text);;
Posted

 
Share this answer
 
Comments
Venkatesh Mookkan 21-Dec-10 1:00am    
I am sure who Univoted this answer. But I am sure this is the best answer. I will 5! this.
Hi,

try this:

C#
cmdupd.Parameters.Add(new SqlParameter("@JoinDate", SqlDbType.DateTime));
cmdupd.Parameters["@JoinDate"].Value = DateTime.Today.ToString("YYYYMMDD",CultureInfo.CreateSpecificCulture("en-US"));


for more information read this thread:

http://stackoverflow.com/questions/336226/string-to-datetime-conversion-in-c[^]
 
Share this answer
 
Comments
Harshini Gunathilake 21-Dec-10 0:45am    
It throws the error
"Failed to convert parameter value from a String to a DateTime."

I'm tryng since few days to correct this :(
JF2015 21-Dec-10 0:47am    
I think only your last snippet would throw an error like this. Can you please post the content of dtpJoinDate.Text?
Harshini Gunathilake 21-Dec-10 1:00am    
It's a date time picker not a textbox actually
Please check the Database Table/SP field (JoinDate) is a DateTime field. I am having a strong feeling that it is not.
 
Share this answer
 
Comments
Harshini Gunathilake 21-Dec-10 0:39am    
Yes, it is datetime :(
Venkatesh Mookkan 21-Dec-10 0:54am    
Please post the table/sp structure in your question.

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