enter a value from dropdownlist to database
I have a checkbox which when enabled the value of the dropdownlist is entered in database and if not enabled a default value should be enterd in the database....
my code is :
if (CheckBox2.Checked)
{
DropDownList1.Enabled = true;
string oeec = DropDownList1.SelectedValue.ToString();
}
else
{
string oeec = "1000";
}
System.Data.SqlClient.SqlConnection dataConnection = new SqlConnection();
dataConnection.ConnectionString =
@"Data Source=JAGMIT-PC\SQLEXPRESS;Initial Catalog=SumooHAgentDB;Integrated Security=True";
System.Data.SqlClient.SqlCommand dataCommand = new SqlCommand();
dataCommand.Connection = dataConnection;
dataCommand.CommandText = ("Insert Policies ( NotifyOnEnvErrorCount) values (@oeec)");
dataCommand.Parameters.AddWithValue("@oeec",oeec);
dataConnection.Open();
dataCommand.ExecuteNonQuery();
dataConnection.Close();
with this i get an error
Error 1 The name 'oeec' does not exist in the current context
Re: enter a value from dropdownlist to database
Re: enter a value from dropdownlist to database
can you tell what did you change to make it work ?