I have a form that a user selects lines to be set up with some information. I would like the user to be able to select all the lines they need and then do a separate insert statement for for each selection as a value for a parameter. For example user Select lines 2,3, and 25 . I need to do fire the insert statement 3 times and each time change the @line parameter to the next line selected. How would I do that? This is as far as I have gotten.
protected void btn_test_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Insert into t_ap_line_setup (line,date) values (@line,getdate())";
//string strLines = "";
// cmd.Parameters.Add("@line", SqlDbType.Int).Value = Convert.ToInt32(strLines);
cmd.Connection = this.sqlConnection1;
this.sqlConnection1.Open();
for (int i = 0; i < lines_list.Items.Count; i++)
{
if (lines_list.Items[i].Selected)
{
cmd.Parameters.Add("@line", SqlDbType.Int).Value = Convert.ToInt32(lines_list.Items[i].Text);
cmd.ExecuteNonQuery();
}
}
this.sqlConnection1.Close();
}
One more thing with the above logic I get two inserts and it only works with one selection. Could someone point me in the right direction?