System. ArgumentException: the length of the input array is greater than the number of columns in this table ., Ansys output multi-column Array

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.