Click here to Skip to main content
15,910,886 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i put a datetimepicker on my form n named it as F_B1.
initialize a variable as below

string f_date = F_B1.Text;


and f_date value is going in a column whose datatype is datetime but i m getting this error

conversion failed when converting datetime from character string
Posted

Don't convert it to a string. Instead of using the Text property of the DateTimePicker, use the Value property - this is already a DateTime so no conversion is needed.
As a general rule, never convert unless you have to: work with DateTime values until you are actually outputting to a screen or printer - they are much more flexible, as well as being smaller!
 
Share this answer
 
Comments
Sweety Khan 18-Jun-11 3:58am    
thanx a lot :) its done by coding this
DateTime f_date = F_B1.Value;
OriginalGriff 18-Jun-11 4:06am    
You're welcome!
Sergey Alexandrovich Kryukov 18-Jun-11 19:08pm    
Correct, a 5.
--SA
Did you use Convert.ToDateTime(f_date) ?
 
Share this answer
 
v2
Comments
Sweety Khan 18-Jun-11 3:57am    
thanx u so much. u realized me tht there is a DateTime datatype in c# :)
arathi_suresh 18-Jun-11 3:59am    
Welcome..Please mark as solution if it worked
Sweety Khan 18-Jun-11 11:28am    
yes i marked it n also vote it

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