想飞的鱼丶 2016-07-26 05:03 采纳率: 0%
浏览 1565

为什么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条回答

  • Go 旅城通票 2016-07-26 05:41
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图的问题
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名