Joma Rajab

Joma Rajab

  • NA
  • 110
  • 51.3k

How to make multiple checkbox add to database

Aug 11 2016 10:53 AM
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  
  1. 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";  
  2.                cmd.Connection = conn;  
  3.                foreach (ListItem item in chkModules.Items)  
  4.                    if (item.Selected == true)  
  5.                    {  
  6.                        conn.Open();  
  7.                        cmd.Parameters.Clear();  
  8.                        cmd.Parameters.AddWithValue("@UId", DropDownList1.SelectedItem.ToString());  
  9.                        cmd.Parameters.AddWithValue("@MId", item.Value.ToString());  
  10.                        cmd.Parameters.AddWithValue("@MName", item.Text.ToString());  
  11.                        chkModules.Visible = false;  
  12.                        cmd.ExecuteNonQuery();  

Answers (5)