ExecuteNonQuery 返回值的问题 调试sql 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果你的语句没问题,就不会跳到catch里面ExecuteNonQuery 指的是受影响的行数,如果没有删除数据,则受影响的行数为0所以你判断是否删除成功应该从受影响行数是否为0来判断 if(list.Count>1){//多条数据的 string instr = "("; for (int i = 0; i < list.Count;i++ ) { instr+=list[i]+","; } instr = instr.Remove(instr.LastIndexOf(","), 1);//截逗号//s1 = s1.Substring(0, s1.Length-1); //去掉最后 instr += ")"; string muti_sqlstr = string.Format("DELETE FROM TB_ResidentBaseInfo WHERE ID IN {0}",instr); int rows = DbHelperSQL.ExecuteSql(muti_sqlstr); if (rows > 1)//因为至少都是2条 { X.Msg.Alert("提示", "成功删除" + rows + "条数据").Show(); this.Store1.DataSource = this.GetDataTable(); this.Store1.DataBind();//重新绑定数据 } else { X.Msg.Alert("提示", "删除失败").Show(); } }else{//单条数据的 string singal_sql =string.Format( " DELETE FROM TB_ResidentBaseInfo WHERE ID='{0}'",list[0]); int sinrows = DbHelperSQL.ExecuteSql(singal_sql); if (sinrows > 0) { X.Msg.Alert("提示", "成功删除1条数据").Show(); this.Store1.DataSource = this.GetDataTable(); this.Store1.DataBind();//重新绑定数据 }else{ X.Msg.Alert("提示", "删除失败").Show(); } } 你先不打断电,用Profiler来跟踪一下你整个删除过程调用的真实语句,分析一下是否T-SQL问题,还是说C#问题 求一个sql语句 急!Sql统计问题 请教一条SQL语句(如何从表A得到表B)? 如何写这个SQL? T-SQL触发器的一些问题 网站使用的sql2000上想做一个负载 请教大侠利用SQL语句如何判断一个数据库中有某个表和一个表中有某个字段? sql server中参数的使用。 如何查询某字段最大值的行记录? 时间类型到底用datetime类型存储好还是用nvarchar存储好 求sql查询语句。高手请进 Myeclipse配置数据库MySQL5.0的问题
ExecuteNonQuery 指的是受影响的行数,如果没有删除数据,则受影响的行数为0
所以你判断是否删除成功应该从受影响行数是否为0来判断
if(list.Count>1){//多条数据的
string instr = "(";
for (int i = 0; i < list.Count;i++ )
{
instr+=list[i]+",";
}
instr = instr.Remove(instr.LastIndexOf(","), 1);//截逗号//s1 = s1.Substring(0, s1.Length-1); //去掉最后
instr += ")";
string muti_sqlstr = string.Format("DELETE FROM TB_ResidentBaseInfo WHERE ID IN {0}",instr);
int rows = DbHelperSQL.ExecuteSql(muti_sqlstr);
if (rows > 1)//因为至少都是2条
{
X.Msg.Alert("提示", "成功删除" + rows + "条数据").Show();
this.Store1.DataSource = this.GetDataTable();
this.Store1.DataBind();//重新绑定数据
}
else
{
X.Msg.Alert("提示", "删除失败").Show();
}
}else{//单条数据的
string singal_sql =string.Format( " DELETE FROM TB_ResidentBaseInfo WHERE ID='{0}'",list[0]);
int sinrows = DbHelperSQL.ExecuteSql(singal_sql);
if (sinrows > 0)
{
X.Msg.Alert("提示", "成功删除1条数据").Show();
this.Store1.DataSource = this.GetDataTable();
this.Store1.DataBind();//重新绑定数据
}else{
X.Msg.Alert("提示", "删除失败").Show();
}
}