且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在数据库中保存日期时间选择器值

更新时间:2022-10-25 08:41:26

试试这个



SqlCommand com = new SqlCommand(插入测试值(@DtValue,con);

com.Parameters .AddWithValue( DtValue,dateTimePicker1.Value.Date);

Want to save datetimepicker value in database and datatype is date. while I am saving this value the error occurred. The error is"Conversion failed when converting date and/or time from character string.". How to solve this error.

SqlCommand com = new SqlCommand("insert into Test values('" + dateTimePicker1.Value.Date + "')", con);


Anyone help me.
Thanking you

Try this

SqlCommand com = new SqlCommand("insert into Test values(@DtValue, con);
com.Parameters.AddWithValue("DtValue",dateTimePicker1.Value.Date);