7

i have a DropDownList that display a collection of subset based on SetID from another ddl and some times it is null. how i can insert null value into database ? i tried with this code but not work:

CmdUpdate.Parameters.Add("@SubsetID",SqlDbType.Int);
if (ddlSubset.Items.Count!=0)
{
  CmdUpdate.Parameters["@SubsetID"].Value=ddlSubset.SelectedValue;
}
esle
{
  CmdUpdate.Parameters["@SubsetID"].Value=null;
}

2 Answers 2

16

Use System.DBNull class:

CmdUpdate.Parameters["@SubsetID"].Value = DBNull.Value;
Sign up to request clarification or add additional context in comments.

Comments

2

Use DBNull:

CmdUpdate.Parameters["@SubsetID"].Value = DBNull.Value;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.