System. ArgumentException: the length of the input array is greater than the number of columns in this table ., Ansys output multi-column Array
Complete error message
System. ArgumentException: the length of the input array is greater than the number of columns in this table.
In System. Data. DataTable. NewRecordFromArray (Object [] value)
In System. Data. DataRowCollection. Add (Object [] values)
In \ MainFrm. parse (OleDbTransaction dbtran, DataTable destTable, String insertCommand, DataRow dr_src, String pKColumnName, Int32 & primaryKeyValue, FilterColumn filterColumn) Location J: \ csProjects \ Main. cs: 2636
At \ MainFrm. ImportDB_ImportTable (OleDbConnection con_src, OleDbTransaction dbtran, String tableName, FilterColumn filterColumn) Position J: \ csProjects \ Main. cs: row number 2573
In \ MainFrm. Loads (OleDbConnection con_src, OleDbTransaction dbtran, String ProjectID_src, Int32 & impContract_exist, Int32 & impContract_succe) Position J: \ csProjects \ Main. cs: Row 2519
In the \ MainFrm. ImportDB_ImportProject (String srcDBFilePath) Location J: \ csProjects \ Main. cs: row number 2382
Error code line
destTable.Rows.Add(dr_src.ItemArray);
The destTable type is System. Data. DataTable.
The dr_src type is System. Data. DataRow.
Error cause
Dr_src contains more columns than destTable.
Solution
Generate new rows based on the structure of the target data table, and fill fields one by one;
DataRow dr_new = destTable.NewRow();foreach (DataColumn dc in destTable.Columns){ if (dr_src.Table.Columns.Contains(dc.ColumnName)) { dr_new[dc.ColumnName] = dr_src[dc.ColumnName]; }}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.