Search code examples
c#.netsqlsql-serverdbnull

SQL Server Update DateTime type to null


Since it's friday my brain must have malfunctioned.

I'm trying to update a column of the type DateTime with the good ol' OleDb, the update always run (changing other column values on the same row) but for some reason the DateTime column refuses to be set to null.

Ofc the column allows null.

I'm using the OleDbParameter constructor to add a new parameter to my command might it be the parameter that refuses to run if the value is null?

I've tried SqlDateTime.Null, DbNull.Value and null as the parameter but nothing sets the value to null, it leaves it untouched or sets it to our beloved 1900-00-01.

any tips and tricks are appreciated


Solution

  • you want to use DBNull.Value

    just like the prior comments you could do something like DateTime? myDate = null;