qq_34418970
想飞的鱼丶
2016-07-26 05:03

为什么ExecuteNonQuery返回0,数据里没改

删除按钮
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’)才能执行

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答