-2

I want to insert a date or a null value into a date time field(SQL).

But I cannot insert the null value.

I want to do this without SP.

6
  • you set the DBNull msdn.microsoft.com/en-us/library/system.dbnull(v=vs.110).aspx Commented Feb 10, 2014 at 6:53
  • dupe - stackoverflow.com/q/13683338/853295 Commented Feb 10, 2014 at 6:56
  • set default value of Date field to null, simple :) Commented Feb 10, 2014 at 6:57
  • update the question with the related code Commented Feb 10, 2014 at 6:58
  • Are you writing SQL (structured query language) and really mean Microsoft SQL Server (the actual product) by this? If yes: please add sql-server tag to make this clear. If not: what database system is this for? Commented Feb 10, 2014 at 6:59

2 Answers 2

1
cmd1.Parameters["@DateTimeParamName"].Value = getDate ?? DBNull.Value;
Sign up to request clarification or add additional context in comments.

Comments

0

you need to set DBNull.Value if you using parameters

cmd.Parameters["@DateTimeParamName"].Value = DBNull.Value

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.