System.ArgumentException: The input array is longer than the number of columns in this table.

Source: Internet
Author: User

Complete error message

System.ArgumentException: The input array is longer than the number of columns in this table.
In System.Data.DataTable.NewRecordFromArray (object[] value)
In System.Data.DataRowCollection.Add (object[] values)
In \mainfrm.importdb_insertrecord (OleDbTransaction Dbtran, DataTable desttable, String InsertCommand, DataRow dr_src, String Pkcolumnname, int32& primarykeyvalue, FilterColumn filtercolumn) location J:\csProjects\Main.cs: line number 2636
In \mainfrm.importdb_importtable (OleDbConnection con_src, OleDbTransaction Dbtran, String tableName, FilterColumn FilterColumn) Location J:\csProjects\Main.cs: line number 2573
In \mainfrm.importdb_importcontract (OleDbConnection con_src, OleDbTransaction Dbtran, String projectid_src, Int32& Impcontract_exist, int32& impcontract_succe) location J:\csProjects\Main.cs: Line No. 2519
In \mainfrm.importdb_importproject (String srcdbfilepath) position J:\csProjects\Main.cs: line number 2382

Error code line
destTable.Rows.Add(dr_src.ItemArray);

The desttable type is: System.Data.DataTable
The type of DR_SRC is: System.Data.DataRow

Cause of error

DR_SRC contains more columns than the number of columns desttable contains.

Solution Solutions

Generates a new row based on the structure of the Target data table, and then fills the fields one by one;

DataRow dr_new = destTable.NewRow();in destTable.Columns){    if (dr_src.Table.Columns.Contains(dc.ColumnName))    {        dr_new[dc.ColumnName] = dr_src[dc.ColumnName];    }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

System.ArgumentException: The input array is longer than the number of columns in this table.

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.