Posted by craig
Wednesday, June 03, 2009 1:05:23 PM
Working with DateTime and the DB can be tricky in C#. The easiest way to insert a DateTime robustly in to the DB is to use a prepared statement
cmd.Parameters.AddWithValue("@Date", DateTime.Now);
2) Inserting a Null Value into the Db
As a second point it, I had a situation where it was important to work with a nullable date time in the DB, in this case DBNull.Value should be used as follows:
cmd.Parameters.AddWithValue("@Date", DBNull.Value);
Copyright 2009 AnyTime