Сначала прости за мой паршивый английский.
Теперь по вопросу, у меня есть набор данных, содержащий 2 таблицы, каждая таблица имеет более сотни полей, есть ли способ вставить все данные в таблицу данных без необходимости назначать каждое поле?.
Я слышал, что адаптер данных может это сделать, но так как источником являются другие данные, я не смог заархивировать это, или я застрял, чтобы присвоить каждому полю переменную?.
В данный момент я сильно сопоставляю источник со вставкой.
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, теперь мне не хватает способа перебора всех данных.