Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 0.88 KB | None | 0 0
  1.     protected void btn1_Click(object sender, EventArgs e)
  2.     {
  3.         List<string> selected = CheckBoxList1.Items.Cast<ListItem>()
  4.             .Where(li => li.Selected)
  5.             .Select(li => li.Value)
  6.             .ToList();
  7.  
  8.         using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
  9.         {
  10.  
  11.             foreach (string item in selected)
  12.             {
  13.  
  14.                 String sqlUpdate = "insert into OficinasHasServicos values (8, @idservico)";
  15.  
  16.                 SqlCommand command = new SqlCommand(sqlUpdate, con);
  17.                 command.Parameters.AddWithValue("@idservico", item.ToString());
  18.                 con.Open();
  19.                 command.ExecuteNonQuery();
  20.                 con.Close();
  21.  
  22.                 lit1.Text += "added " + item.ToString() + "<br>";
  23.  
  24.  
  25.         }
  26.  
  27.  
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement