Saving Multiple CheckBoxes in Single Column Database

  1. private void button1_Click(object sender, EventArgs e)   
  2. {  
  3.     string s = "";  
  4.     foreach(Control c in this.Controls)   
  5.     {  
  6.         if (c is CheckBox)   
  7.         {  
  8.             CheckBox b = (CheckBox) c;  
  9.             if (b.Checked) {  
  10.                 //s = b.Text + s; // if u want to add spaces or seperation between ur selection u can add like this   
  11.                 s = b.Text + "," + s;  
  12.             }  
  13.         }  
  14.     }  
  15.     MessageBox.Show(s); //if u want to save in database u can directly save string value s   
  16.   
  17.     cn.Open();  
  18.     SqlCommand cmd = new SqlCommand("insert into mcombo values('" + s + "')", cn);  
  19.     cmd.ExecuteNonQuery();  
  20.     cn.Close();  
  21. }  
  22.   
  23. //videoor go through this youtube  
  24. videohttps: //www.youtube.com/watch?v=hJ5m-PH6td4  
G
o through this Youtube video.