I have 6 DropDownList that have the following values;
ABC,DEF,GHI,JKL,MNO,PQR
I want to insert the values from ddl1, ddl2, ddl3, ddl4, ddl5 and ddl6 into my SQL table by taking the value from each dropdownlist.
I've currently got the following but need to adapt it to insert the values from each individual dropdownlist rather than the same value:
SqlConnection sqlCon = new SqlConnection("Data Source=***; User ID=***; MultipleActiveResultSets=True; Password=***; Initial Catalog=PMRDA;");
try
{
sqlCon.Open();
foreach (string str in AllOptions)
{
SqlCommand cmd = new SqlCommand("INSERT INTO lboard(eventType, date, college) values (@eventType, GETDATE(), @college)", sqlCon);
SqlParameter eventType = cmd.Parameters.Add("@eventType", SqlDbType.VarChar);
SqlParameter college = cmd.Parameters.Add("@college", SqlDbType.Char);
eventType.Value = ddlEventType.SelectedItem.Value;
college.Value = ddl5.SelectedItem.Value;
cmd.ExecuteNonQuery();
}
LabelStatus.Text = "Submitted Succesfully";
}
catch(Exception ex)
{
LabelStatus.Text = ex.Message;
}
finally
{
sqlCon.Close();
}