日期:2014-05-20  浏览次数:21430 次

替换占位符
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+ ", "? ");