日期:2014-05-17  浏览次数:20617 次

插入问题重复问题,急??
DataSet setInsert = WebData1.dataSet(insertsqls);
   
  foreach (DataRow drInsert in setInsert.Tables[0].Rows)
  {
  //插入资料表sql--start
   
  sb.Append("var code = '', name = '', type = '', slkcode = '', createdt = '', createby = '', salesacc = '', sysed = '', sysud = '', sales = '', areacode = '';");
  sb.Append("code = '" + drInsert["customer_code"].ToString() + "';" +
  "name = '" + drInsert["customer_name"].ToString() + "';" +
  "type = '" + drInsert["customer_type"].ToString() + "';" +
  "slkcode = '" + drInsert["slk_code"].ToString() + "';" +
  "createdt = '" + drInsert["create_dt"].ToString() + "';" +
  "createby = '" + drInsert["create_by"].ToString() + "';" +
  "salesacc = '" + drInsert["sales_account"].ToString() + "';" +
  "sysed = '" + drInsert["SYSDE"].ToString() + "';" +
  "sysud = '" + drInsert["SYSUD"].ToString() + "';" +
  "sales = '" + drInsert["sales"].ToString() + "';" +
  "areacode = '" + drInsert["Area_code"].ToString() + "';");
  sb.Append("var insertSql='INSERT INTO Cus_ (customer_code, customer_name, customer_type, slk_code, create_dt, create_by, sales_account, SYSDE, SYSUD,sales,Area_code) VALUES (?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?)';");
  sb.Append("db.transaction(function(tt){" +
  "tt.executeSql(insertSql,[code,name,type,slkcode,createdt,createby,salesacc,sysed,sysud,sales,areacode],function(){},function(){});" +
  "});");
  }


插入数据结果如下:
C0000002845-酷l-王
C0000002845-酷l-王
C0000002845-酷l-王
C0000002845-酷l-王
上边的循环好像没错,为什么插入的数据一直都是重复的,哪些高人指点下。

------解决方案--------------------
重复插入 肯定是你的sb 没有被清空 你的sb 是一直在循环加 字符
改下就好了
C# code

 foreach (DataRow drInsert in setInsert.Tables[0].Rows)
  {
    StringBulid sb=new StringBulid()
}