How to insert null in datetime type column in sql server

后端 未结 11 2172
醉酒成梦
醉酒成梦 2021-02-20 15:23

I have a table in which there are some datetime type columns. I use a stored procedure to insert values into the table. In the stored procedure I have variables that accept null

11条回答
  •  佛祖请我去吃肉
    2021-02-20 16:05

    To pass null value to db you can use DBNull.Value. Please try this

     if (string.IsNullOrWhiteSpace(InsertDate.Text))
      {
       cmd1.Parameters["@InsertDate"].Value =DBNull.Value;
      }
     else
      {
       cmd1.Parameters["@InsertDate"].Value = InsertDate.Text;
      }
    

提交回复
热议问题