Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

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….

Advertisements

2 Responses to “Insert Null values into datetime column of SQL SERVER using asp.net”

  1. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: