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);
Comments
Post a Comment