执行mySQL的DELETE语句 进行批量删除
执行mySQL的DELETE语句 进行批量删除
mysql客户端执行语句:
delete from tb_acs_plan where ID in (12,9) and ACSPID not in (select distinct(ACSPID) from tb_acs_basic);
c#代码编写语句使用ado删除:
当前我获取到的id形式:

//将获取到的id过滤下为可拼接类型,否则执行mysql的delete语句失败 string iDstr = entity.iID.UsSQLSearchBadCharV2_In(); //前半句为删除语句 后半句为mysql中获取受影响行数(成功删除几行返回数字几) sSQL = "delete from tb_acs_plan where ID in ("+ iDstr + ") and ACSPID not in (select distinct(ACSPID) from tb_acs_basic);select row_count();";
// // 摘要: // 过滤IN格式 // // 参数: // str: [Description("过滤IN格式,对于ZoneID不能过滤")] public static string UsSQLSearchBadCharV2_In(this string str) { return UsSQLCharMethod.UsSearchBadChar(str, isIn: true); }
// // 摘要: // 对SQL参数的字符串进行过滤 // // 参数: // str: // // isIn: public static string UsSearchBadChar(string str, bool isIn = false) { if (string.IsNullOrEmpty(str)) { return ""; } str = str.Replace("--", "").Replace(".", "").Replace("'", "") .Replace(" ", "") .Replace("?", "") .Replace("%", "") .Replace("=", ""); str = str.Replace("--", ""); if (!isIn) { str = str.Replace(",", ""); } str = str.Trim(); return str; }
执行成功,并返回受影响行数(删除几行返回几通过select row_count();实现)
本文来自博客园,作者:じ逐梦,转载请注明原文链接:https://www.cnblogs.com/ZhuMeng-Chao/p/17029404.html

浙公网安备 33010602011771号