I need to add more one selected item from checkbox to database but when I select more one I could not for one Item it works fine
this the code
please help
thanks
- cmd.CommandText = "If Not Exists(select * from dbo.ModuleRelation where UId=@UId and MId=@MId) Begin insert into dbo.ModuleRelation (UId, MId, MName) values(@UId, @MId, @MName) End";
- cmd.Connection = conn;
- foreach (ListItem item in chkModules.Items)
- if (item.Selected == true)
- {
- conn.Open();
- cmd.Parameters.Clear();
- cmd.Parameters.AddWithValue("@UId", DropDownList1.SelectedItem.ToString());
- cmd.Parameters.AddWithValue("@MId", item.Value.ToString());
- cmd.Parameters.AddWithValue("@MName", item.Text.ToString());
- chkModules.Visible = false;
- cmd.ExecuteNonQuery();