I want to insert a null value into the database, but i keep getting annoying errors. Let me explain the situation first:
I am filling an ddl with values form the database. The column contains NULL values. The ddl isn't filled with these NULL values so I add them manually (ddlSubConsolidations.Items.Insert(0, "");). Now I want to add all the values to the database by the Button Click event:
protected void btnAdd_Click(object sender, EventArgs e)
{
// Some Validation rules
if (ValidateName() && ValidateExists())
{
// If the selected value in the ddl is empty the column needs to be filled with an Null value.
if (ddlParent.SelectedValue.ToString() == "")
{
FireInsert(DBNull.Value.ToString());
}
// Else the selected value has to be inserted into the database.
else
{
FireInsert(ddlParent.SelectedValue.ToString());
}
}
}
private void FireInsert(string CheckedDdlParent)
{
dc.ExecuteSQL(queries.InsertConsolidation(CheckedDdlParent, txtName.Text, ddlCurrency.SelectedValue.ToString()));
}
Now I get the error. Does somebody have any ideas how to get a Null value in the database by using this code?
I know that I can execute the insert in the if and the else, but I want to know if its possible this way.
And sorry for the bad written english :-$ .