On button click no values inserts into the database.
When i Response.Write the (insertSQL ) i got this message
INSERT INTO tracking (stockid,packinglist,datesent,location,comment,status) VALUES (@stockid,@packinglist,@datesent,@location,@comment,@status)
INSERT INTO tracking (stockid,packinglist,datesent,location,comment,status) VALUES (@stockid,@packinglist,@datesent,@location,@comment,@status)
INSERT INTO tracking (stockid,packinglist,datesent,location,comment,status) VALUES (@stockid,@packinglist,@datesent,@location,@comment,@status)
protected void Button1_Click(object sender, EventArgs e)
{
List<string> stockid = (List<string>)Session["id"];
int added = 0;
for (int i = 0; i < stockid.Count; i++)
{
string insertSQL = "INSERT INTO tracking (stockid,packinglist,datesent,location,comment,status) VALUES (@stockid,@packinglist,@datesent,@location,@comment,@status)";
String connectionString = "data source=NERO-SIGBENU\\SQLEXPRESS01; Initial Catalog=arpackaging;Integrated Security=True;";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(insertSQL, con);
cmd.Parameters.AddWithValue("@stockid", stockid[i]);
cmd.Parameters.AddWithValue("@packinglist", TextBox1.Text);
cmd.Parameters.AddWithValue("@datesent", Session["Time1"].ToString());
cmd.Parameters.AddWithValue("@location", DropDownList1.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@comment", TextBox2.Text);
cmd.Parameters.AddWithValue("@status", 1);
try
{
con.Open();
Response.Write(insertSQL);
added += cmd.ExecuteNonQuery();
}
catch (Exception)
{
}
finally
{
con.Close();
}
}
}