lingers says:
protected
void
ImageButton3_Click(
object
sender, EventArgs e)
{
string
ids = hfCheckedIds.Value;
foreach
(
string
id
in
ids.Split(
','
))
{
SqlConnection con1 =
new
SqlConnection(
"data source=NERO-SIGBENU\\SQLEXPRESS01; Initial Catalog=arpackaging;Integrated Security=True;"
);
SqlCommand cm =
new
SqlCommand();
cm.Connection = con1;
con1.Open();
cm.CommandType = CommandType.Text;
cm.CommandText =
"SELECT id FROM job WHERE id=@id "
;
cm.Parameters.AddWithValue(
"@id"
, ids);
Session[
"ppp"
] = Convert.ToInt32(cm.ExecuteScalar());
con1.Close();
using
(SqlConnection con =
new
SqlConnection(
"data source=NERO\\SQLEXPRESS01; Initial Catalog=kaging;Integrated Security=True;"
))
{
con.Open();
SqlCommand cmd =
new
SqlCommand(
"delete from job where id='"
+ ids +
"' "
, con);
cmd.ExecuteNonQuery();
con.Close();
}
}
BindDummyRow();
}
}
Replace above with below code.
protected void ImageButton3_Click(object sender, EventArgs e)
{
string ids = hfCheckedIds.Value;
foreach (string id in ids.Split(','))
{
SqlConnection con1 = new SqlConnection("data source=NERO-SIGBENU\\SQLEXPRESS01; Initial Catalog=arpackaging;Integrated Security=True;");
SqlCommand cm = new SqlCommand();
cm.Connection = con1;
con1.Open();
cm.CommandType = CommandType.Text;
cm.CommandText = "SELECT id FROM job WHERE id=@id ";
cm.Parameters.AddWithValue("@id", id);
Session["ppp"] = Convert.ToInt32(cm.ExecuteScalar());
con1.Close();
using (SqlConnection con = new SqlConnection("data source=NERO\\SQLEXPRESS01; Initial Catalog=kaging;Integrated Security=True;"))
{
con.Open();
SqlCommand cmd = new SqlCommand("delete from job where id=@Id", con);
cmd.Parameters.AddWithValue("@Id", id);
cmd.ExecuteNonQuery();
con.Close();
}
}
BindDummyRow();
}
You need to pass id instead of ids.
cm.Parameters.AddWithValue("@id", id);