Insert Null values into datetime column of SQL SERVER using asp.net
Posted by Viral Sarvaiya on December 29, 2009
Sometimes we will get the situation where we must insert NULL into datetime column in sql server.
Follow these steps to do that:
1) First Include the namespace:
using System.Data.SqlTypes;
2) Declare
System.Data.SqlTypes.SqlDateTime getDate; getDate = SqlDateTime.Null;
3) Insert using command Parameters
cmd11.Parameters.AddWithValue(“@encashed_date”, getDate);
with this procedure you can insert the NULL value in datetime datatype column.
enjoy coding….



Murali said
It is throwing error………cannot able to convert datetime to system.iconvertible…………..any idea on how to overcome this issue ……..
Viral Sarvaiya said
Hi Murali,
that datetime field have to allow null.
and use like
string strQuery = “insert into tblName(DatetimeField) values (” + SqlDateTime.Null + “)”;
Hope this will helps ypu.