日期:2014-05-19  浏览次数:20388 次

c# 用存储过程 插入 datetime空字段
我写程序用   存储过程插入字段
SqlCommand   cm1   =   new   SqlCommand( "KHupdate ",   cn1);
cm1.CommandType   =   CommandType.StoredProcedure;

但我从
cm1.Parameters[ "@S_Date "].Value   =   this.TB_S_Date.Text;
传递字段

如果this.TB_S_Date.Text   是空值
就会出现
"该字符串未被识别为有效的   DateTime "
请问如何解决

谢谢

------解决方案--------------------

if (!string.IsNullOrEmpty(this.TB_S_Date.Text))
{
cm1.Parameters[ "@S_Date "].Value = DateTime.Parse(this.TB_S_Date.Text);
}
else
{
//cm1.Parameters[ "@S_Date "].Value = DBNull.Value;//如果字段可以为空.
//或
  //提示出错
}