Ye Myat Aung
Ye Myat Aung

Reputation: 1853

Store Null value in SQL Server

I have a row with nullable columns in my table in SQL Server. I tried to store values like this.

if (chkQCE3AS1.Checked)
   cmd.Parameters.AddWithValue("QCEA1S1", selectedID);
else
   cmd.Parameters.AddWithValue("QCEA1S1", "");

But that would store a space in the column. What would be another way to store a null value? Or is it even a good idea?

Upvotes: 1

Views: 772

Answers (1)

Pranay Rana
Pranay Rana

Reputation: 176956

Make use of DBNull that will do your task.

        if (chkQCE3AS1.Checked)
            cmd.Parameters.AddWithValue("QCEA1S1", selectedID);
        else
            cmd.Parameters.AddWithValue("QCEA1S1", DBNull.Value);

Upvotes: 9

Related Questions