首先对不起我的糟糕英语。dataadapter填表(as400)
现在在这个问题上,我有一个数据集包含2个表,每个表都有一个hundread字段有没有办法将所有数据插入到数据表中而不必分配每个字段?
我听说dataadapter可以实现这一点,但由于源是另一个数据,我一直无法将其归档,或者我坚持要为每个字段赋一个变量?
此刻我强烈地将源映射到插入。
try
{
connection.Open();
DateTime fecha1 = Convert.ToDateTime(ds.Tables[0].Rows[0][4].ToString());
DateTime fecha2 = Convert.ToDateTime(ds.Tables[0].Rows[0][12].ToString());
DateTime fecha3 = Convert.ToDateTime(ds.Tables[0].Rows[0][61].ToString());
query = "INSERT INTO HDZSNC.RELTRM VALUES ('" + ds.Tables[0].Rows[0][0] + "','"
+ ds.Tables[0].Rows[0][1] + "'," + ds.Tables[0].Rows[0][2] + ",'" + ds.Tables[0].Rows[0][3] + "',"
+ String.Format("{0:yyyyddMM}", fecha1) + "," + ds.Tables[0].Rows[0][5] + ",'" + ds.Tables[0].Rows[0][6] + "',"
+ ds.Tables[0].Rows[0][7] + "," + ds.Tables[0].Rows[0][8] + "," + ds.Tables[0].Rows[0][9] + ","
+ ds.Tables[0].Rows[0][10] + "," + ds.Tables[0].Rows[0][11] + "," + String.Format("{0:yyyyddMM}", fecha2) + ","
+ ds.Tables[0].Rows[0][13] + "," + ds.Tables[0].Rows[0][14] + "," + ds.Tables[0].Rows[0][15] + ","
+ ds.Tables[0].Rows[0][16] + "," + ds.Tables[0].Rows[0][17] + "," + ds.Tables[0].Rows[0][18] + ","
+ ds.Tables[0].Rows[0][19] + "," + ds.Tables[0].Rows[0][20] + "," + ds.Tables[0].Rows[0][21] + ","
+ ds.Tables[0].Rows[0][22] + "," + ds.Tables[0].Rows[0][23] + "," + ds.Tables[0].Rows[0][24] + ","
+ ds.Tables[0].Rows[0][25] + "," + ds.Tables[0].Rows[0][26] + "," + ds.Tables[0].Rows[0][27] + ","
+ ds.Tables[0].Rows[0][28] + "," + ds.Tables[0].Rows[0][29] + "," + ds.Tables[0].Rows[0][30] + ","
+ ds.Tables[0].Rows[0][31] + "," + ds.Tables[0].Rows[0][32] + "," + ds.Tables[0].Rows[0][33] + ","
+ ds.Tables[0].Rows[0][34] + "," + ds.Tables[0].Rows[0][35] + "," + ds.Tables[0].Rows[0][36] + ","
+ ds.Tables[0].Rows[0][37] + "," + ds.Tables[0].Rows[0][38] + "," + ds.Tables[0].Rows[0][39] + ","
+ ds.Tables[0].Rows[0][40] + "," + ds.Tables[0].Rows[0][41] + "," + ds.Tables[0].Rows[0][42] + ","
+ ds.Tables[0].Rows[0][43] + "," + ds.Tables[0].Rows[0][44] + "," + ds.Tables[0].Rows[0][45] + ","
+ ds.Tables[0].Rows[0][46] + "," + ds.Tables[0].Rows[0][47] + "," + ds.Tables[0].Rows[0][48] + ","
+ ds.Tables[0].Rows[0][49] + "," + ds.Tables[0].Rows[0][50] + "," + ds.Tables[0].Rows[0][51] + ","
+ ds.Tables[0].Rows[0][52] + "," + ds.Tables[0].Rows[0][53] + "," + ds.Tables[0].Rows[0][54] + ","
+ ds.Tables[0].Rows[0][55] + "," + ds.Tables[0].Rows[0][56] + "," + ds.Tables[0].Rows[0][57] + ","
+ ds.Tables[0].Rows[0][58] + "," + ds.Tables[0].Rows[0][59] + "," + ds.Tables[0].Rows[0][60] + ","
+ String.Format("{0:yyyyddMM}", fecha3) + "," + ds.Tables[0].Rows[0][62] + "," + ds.Tables[0].Rows[0][63] + ","
+ ds.Tables[0].Rows[0][64] + "," + ds.Tables[0].Rows[0][65] + "," + ds.Tables[0].Rows[0][66] + ","
+ ds.Tables[0].Rows[0][67] + "," + ds.Tables[0].Rows[0][68] + "," + ds.Tables[0].Rows[0][69] + ","
+ ds.Tables[0].Rows[0][70] + "," + ds.Tables[0].Rows[0][71] + "," + ds.Tables[0].Rows[0][72] + ","
+ ds.Tables[0].Rows[0][73] + "," + ds.Tables[0].Rows[0][74] + "," + ds.Tables[0].Rows[0][75] + ","
+ ds.Tables[0].Rows[0][76] + "," + ds.Tables[0].Rows[0][77] + "," + ds.Tables[0].Rows[0][78] + ","
+ ds.Tables[0].Rows[0][79] + "," + ds.Tables[0].Rows[0][80] + "," + ds.Tables[0].Rows[0][81] + ","
+ ds.Tables[0].Rows[0][82] + "," + ds.Tables[0].Rows[0][83] + "," + ds.Tables[0].Rows[0][84] + ","
+ ds.Tables[0].Rows[0][85] + "," + ds.Tables[0].Rows[0][86] + "," + ds.Tables[0].Rows[0][87] + ","
+ ds.Tables[0].Rows[0][88] + "," + ds.Tables[0].Rows[0][89] + "," + ds.Tables[0].Rows[0][90] + ","
+ ds.Tables[0].Rows[0][91] + "," + ds.Tables[0].Rows[0][92] + "," + ds.Tables[0].Rows[0][93] + ","
+ ds.Tables[0].Rows[0][94] + "," + ds.Tables[0].Rows[0][95] + "," + ds.Tables[0].Rows[0][96] + ","
+ ds.Tables[0].Rows[0][97] + "," + ds.Tables[0].Rows[0][98] + "," + ds.Tables[0].Rows[0][99] + ","
+ ds.Tables[0].Rows[0][100] + "," + ds.Tables[0].Rows[0][101] + "," + ds.Tables[0].Rows[0][102] + ","
+ ds.Tables[0].Rows[0][103] + "," + ds.Tables[0].Rows[0][104] + "," + ds.Tables[0].Rows[0][105] + ","
+ ds.Tables[0].Rows[0][106] + "," + ds.Tables[0].Rows[0][107] + ")";
oledbAdapter.InsertCommand = connection.CreateCommand();
oledbAdapter.InsertCommand.CommandText = query;
oledbAdapter.InsertCommand.ExecuteNonQuery();
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("No se puede abrir la coneccion a 400 " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
编辑:来源是我试图将数据复制到AS400数据库,现在我很想念如何与所有的数据表遍历一个访问文件。
显示代码,请 – Icarus
你的英语是没有问题的,但目前还不清楚你想要达到的目标。它是一个强类型数据集,源是什么,源和目标是相同的方案? –
@Tim Schemelter:多年来我一直没有和编程联系,是的数据集是强类型的,源有不同的方案(老实说,他们告诉我它是相同的,但事实并非如此)。 – Enrique