SQL 替换占位符
string strSql = "insert into test_table"
+"(zdsxh,zdsbm,mc,fzrbh,bxrbh,bxrq,sjfrom,sjto)values"
+"(@zdsxh,@zdsbm,@mc,@fzrbh,@bxrbh,@bxrq,@sjfrom,@sjto)";
将strSql替换成
string strSql = "insert into test_table"
+"(zdsxh,zdsbm,mc,fzrbh,bxrbh,bxrq,sjfrom,sjto)values"
+"(?,?,?,?,?,?,?,?)";
替换占位符
使用正则表达式:
strSql = Regex.Replace(strSql , @"@[^,]*,", "?,", RegexOptions.IgnoreCase);
要加上
using System.Text.RegularExpressions;
替换占位符
string strSql = "insert into test_table"
+ "(zdsxh,zdsbm,mc,fzrbh,bxrbh,bxrq,sjfrom,sjto)values"
+ "(@zdsxh,@zdsbm,@mc,@fzrbh,@bxrbh,@bxrq,@sjfrom,@sjto)";
strSql = Regex.Replace(strSql, "@\\w+", "?");
+"(zdsxh,zdsbm,mc,fzrbh,bxrbh,bxrq,sjfrom,sjto)values"
+"(@zdsxh,@zdsbm,@mc,@fzrbh,@bxrbh,@bxrq,@sjfrom,@sjto)";
将strSql替换成
string strSql = "insert into test_table"
+"(zdsxh,zdsbm,mc,fzrbh,bxrbh,bxrq,sjfrom,sjto)values"
+"(?,?,?,?,?,?,?,?)";
替换占位符
使用正则表达式:
strSql = Regex.Replace(strSql , @"@[^,]*,", "?,", RegexOptions.IgnoreCase);
要加上
using System.Text.RegularExpressions;
替换占位符
string strSql = "insert into test_table"
+ "(zdsxh,zdsbm,mc,fzrbh,bxrbh,bxrq,sjfrom,sjto)values"
+ "(@zdsxh,@zdsbm,@mc,@fzrbh,@bxrbh,@bxrq,@sjfrom,@sjto)";
strSql = Regex.Replace(strSql, "@\\w+", "?");