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

■■■■■送分行动!DataSet中记录集写入一张数据表■■■■■■
有一DataSet,想遍历后写入另一张表中,谢谢。
需要代码,非常感谢

------解决方案--------------------
sCmd += " insert utsl.dbo.BorMatList ";
for (int i = 0; i < dgMatList.Items.Count; i++)
{
sCmd += " select " + Request.QueryString[ "id "].ToString();
sCmd += " , ' " + dgMatList.Items[i].Cells[(int)Eum_SelMat.col_serno].Text + " ' ";
sCmd += " , ' " + dgMatList.Items[i].Cells[(int)Eum_SelMat.col_pm].Text + " ' ";
sCmd += " , ' " + dgMatList.Items[i].Cells[(int)Eum_SelMat.col_xh].Text + " ' ";
sCmd += " , ' " + dgMatList.Items[i].Cells[(int)Eum_SelMat.col_gg].Text + " ' ";
sCmd += " , ' " + dgMatList.Items[i].Cells[(int)Eum_SelMat.col_appAm].Text + " ' ";
sCmd += " ,null ";
sCmd += " , ' " + dgMatList.Items[i].Cells[(int)Eum_SelMat.col_reason].Text + " ' ";
sCmd += " ,null,null ";
sCmd += " union all ";

}

sCmd = sCmd.Substring(1, sCmd.Length - " union all ".Length);
}
------解决方案--------------------
不知道可不可行,你先试试看

protected OleDbConnection conn = new OleDbConnection( "provider= 'aa ';database= 'bb ';uid= 'cc ';pwd= 'dd '; ");

for (int intILoop = 0; intILoop < DataSetA.NameA.Rows.Count; intILoop++){

string sqlStr = "INSERT INTO TableA(Id1,Id2,Id3) VALUES ( ' "

+DataSetA.NameA.Rows[intILoop][ "Columns1 "].ToString
+ " ', ' "+DataSetA.NameA.Rows[intILoop][ "Columns2 "].ToString
+ " ', ' "+DataSetA.NameA.Rows[intILoop][ "Columns3 "].ToString

+ " ') ";

conn.Open();

OleDbCommand comm = new OleDbCommand(sqlStr,conn);

comm.ExecuteNonQuery();

}