删除按钮
protected void btnDelete_Click(object sender, EventArgs e)
{
string id = "";
foreach(GridViewRow item in GridView1.Rows)
{
CheckBox cb =(CheckBox)item.FindControl("ck");
if (cb.Checked)
{
id+= item.Cells[2].Text+",";
}
}
string BM=id.TrimEnd(',');
string sql = "delete from tb_bookInfo where bookBarCode in(@code)";
SqlParameter[] para ={
new SqlParameter("@code",BM)
};
if(BLL.Delete.ExecuteNonQuery(sql,para)>0)
{
GetBook();
this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('删除成功')", true);
}
}
if (co.State == ConnectionState.Closed)
{
co.Open();
}
SqlCommand comm = new SqlCommand(sql,co);
comm.Parameters.AddRange(para);
try
{
int i = comm.ExecuteNonQuery();
return i;
}
catch (Exception)
{
throw;
}
数据库里的@code对应的是varchar,
调试时发现@code是(111111,1111112)
数据库里必须是(‘111111’,‘11111112’)才能执行