Hi firends,
I wanna send a DataTime value to DateTime field of DB
but my program has an error : Conversion failed when converting datetime from character string
Thanks....
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Subhendu DeRank #1,108 · 1.7K reputationPosted Dec 9, 2010, 9:23 PM EST
You have DateTime field in DB. Now if you are using stored procedure then make the parameter as dbtype.datetime/dbtype.date and if you are using sql query try to use parameterized query and make the as dbtype.datetime/dbtype.date
When you are passing datetime from c# code, use Convert.ToDateTime(
Try it and let me know, if it solves your problem or not.
Thanks.....
Santhosh NRank #4,788 · 325 reputationPosted Dec 9, 2010, 9:24 PM EST
Use this convert your datatime field to convert to desired format
ToString(mm/dd/yyyy ");
shima32 reputationPosted Dec 10, 2010, 2:30 AM EST
I convert my date to DateTime , but i have this error yet!
Conversion failed when converting datetime from character string
dear santosh ,
whats your mean from this? "Use this convert your datatime field to convert to desired format
ToString(mm/dd/yyyy "); "
Subhendu DeRank #1,108 · 1.7K reputationPosted Dec 10, 2010, 2:41 AM EST
Sample data what u want to add to table.
Thanks.....
Suthish NairRank #92 · 22.8K reputationPosted Dec 10, 2010, 4:43 AM EST
Or post your code
Santhosh NRank #4,788 · 325 reputationPosted Dec 10, 2010, 5:39 AM EST
yourdatevalue.ToString(mm/dd/yyyy ");
shima32 reputationPosted Dec 10, 2010, 12:13 PM EST
I need a pattern such as mm/dd/yyyy , but i dont know how use this one?!
Suthish NairRank #92 · 22.8K reputationPosted Dec 11, 2010, 9:38 AM EST
http://www.csharp-examples.net/string-format-datetime/
http://en.csharp-online.net/CSharp_Format_Specifiers%E2%80%94DateTime_Format_Specifiers