如何在数据库中保存日期时间选择器值 [英] How save datetime picker value in database

查看:63
本文介绍了如何在数据库中保存日期时间选择器值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想要在数据库中保存datetimepicker值,数据类型是日期。我保存此值时发生错误。错误是从字符串转换日期和/或时间时转换失败。。如何解决这个错误。



 SqlCommand com = new SqlCommand(插入测试值('+ dateTimePicker1.Value.Date + '),con); 



任何人帮助我。

感谢你

解决方案

试试这个



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);


这篇关于如何在数据库中保存日期时间选择器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆