如何使用maskedtextbox在访问数据库中插入空日期 [英] How to insert null date in access db using maskedtextbox
本文介绍了如何使用maskedtextbox在访问数据库中插入空日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi all,
How to insert null date in access db using maskedtextboxi want to insert null date into access database for that
im using masked textbox same way i need to update suppose user enter blank cheque_date but he want to update cheque_date so he can be update cheque_date also after retrieving data i want update code also for this
我尝试过: < br $> b $ b
插入代码:
What I have tried:
Insert Code :
if (txtmaskchequedate.Text == "")
{
cmd.Parameters.AddWithValue("@Cheque_Date", DBNull.Value);
}
else
{
cmd.Parameters.AddWithValue("@Cheque_Date", txtmaskchequedate.Text);
}
推荐答案
我设置格式:短路到访问数据库并运行跟随代码,在两者中成功执行方式:maskedtextfield空或填充
i set format :shortdate into access database and run follow code its executed successfully in both way either maskedtextfield empty or filled
DateTime chequeDate;
var value = (object)DBNull.Value;
if (DateTime.TryParseExact(txtmaskchequedate.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out chequeDate))
{
value = chequeDate;
}
cmd.Parameters.AddWithValue("@Cheque_Date", value);
这篇关于如何使用maskedtextbox在访问数据库中插入空日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文