how to pass null value in sql from c#

Its a very common scenario when we do not pass any value for a column during db insert it places NULL there for that column. But sometimes situation occurs when we programatically want to insert a NULL for a perticular column in table. And this the way to do this : Just use DBNull.Value in place of the value for that column. Check a tiny example, here I want to update a log table, i am updating the User Id and Session Id, and want to set other values to be NULL.


string msg = (string)SqlHelper.ExecuteScalar(Config.XcatLinkAccountDB, "spInsertUpdateLog", Convert.ToInt32(Session["LoginUserId"]), Convert.ToString(Session.SessionID), DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, flag);
Advertisements

Say something : I accept all the "Humer&Critic"

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