简体   繁体   中英

How can we pass a empty Value to dateTime Parameter to a stored procedure from c#

错误 How can we pass a empty Value to dateTime Parameter to a stored procedure EndDate=null:

da.SelectCommand.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = EndDate

As like the error message says it is not possible to convert the null or DbNull.Value to DateTime if you specify the expected datatype as SqlDbType.DateTime in add method. So better option is AddWithValue. Use like the following:

command.Parameters.AddWithValue("@dateparameter", DBNull.Value);

For more link

Try Below Code

  da.SelectCommand.Parameters.Add("@StartDate", SqlDbType.NVarChar).Value 
= StartDate.ToString("dd-MMM-yyyy");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM