Thursday, June 24, 2010

Read /write NULL Datetime in Sql Server by C#

When you have to insert or read NULL datetiem from sql server then in that case.

Use Namespace:using System.Data.SqlTypes;

declare a variable SqlDateTime sqlNullDate;

for INSERT
if (txtSessionStartDate.Text == "")
sessionsOBJ.sDate = sqlNullDate;
else
sessionsOBJ.sDate = Convert.ToDateTime(txtSessionStartDate.Text);

and read would work normally.

No comments:

Post a Comment