日期:2014-05-18  浏览次数:20890 次

代码错误请教~!
oraString = @"select * from GHTJSBB,申报信息 where Z_id='" + Z_id + "'and 申报信息.ref_admin_id=GHTJSBB.ref_admin_id";
  ds = DbHelperOra.Query(oraString);
  accString = "select * from " + Form_name + "";
  _ds = DbHelperOleDb.Query(accString);
  if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  {
  for (i = 1; i< ds.Tables[0].Columns.Count; i++)
  {
  for (j = 0; j < _ds.Tables[0].Columns.Count; j++)
  {
  string yewu = ds.Tables[0].Rows[0][i].ToString();
  string yewu1 = _ds.Tables[0].Columns[j].ToString();
  //string id = _ds.Tables[0].Columns[28].ToString();
  if (ds.Tables[0].Columns[i].ToString() == _ds.Tables[0].Columns[j].ToString())
  {
  //tt = "insert into " + Form_name + "("+yewu1+") values('" + yewu + "')";
  //DbHelperOleDb.ExecuteSql(tt); 

  tt = "update " + Form_name + " set " + yewu1 + " = '" + yewu + "' where id =1";
  DbHelperOleDb.ExecuteSql(tt);

  }
  }
  }

想用dataset做循环把一个表的数据插入到另外1个表中。
当我写这两行代码时,结果数据在插入时每行插了一个字段,插了好多行。。。。(本来数据应该是一行。)
//tt = "insert into " + Form_name + "("+yewu1+") values('" + yewu + "')";
  //DbHelperOleDb.ExecuteSql(tt); 

而用带update的代码时,数据表中无记录。。。。

  tt = "update " + Form_name + " set " + yewu1 + " = '" + yewu + "' ";
  DbHelperOleDb.ExecuteSql(tt);

请大家给看下哪写错了。。。谢谢~!

------解决方案--------------------
内层循环拼串,外层循环执行SQL