Error in ColumnMapping does not match up with any column in the source or destination in ADO.NET C#

asked 2021-10-21T06:09:31.487+00:00
Gani_tpt 1,201 Reputation points

I have Dataset and trying to move into SQL Server table using Bulk Option. What is the problem in the loop.

The loop (top loop) will be executing first time and inserting the record into the table without any error. where as the looping (top loop) the second time, i am getting the below error.

ERROR : System.InvalidOperationException : 'The given ColumnMapping does not match up with any column in the source or destination.'

Employee column Details (DataSet)


for (int i = 1; i <= 10; i++)
    bulk.DestinationTableName = "tblEmployee";
    foreach (DataColumn col in DataSet.Tables[0].Columns)
      bulk.ColumnMappings.Add(col.ColumnName, col.ColumnName);


pls. give us the guidance where is the problem in the above code.

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
6,905 questions
No comments
{count} votes

Accepted answer
  1. answered 2021-10-21T07:13:22.957+00:00
    Viorel 82,136 Reputation points

    Try executing bulk.ColumnMappings.Clear( ) before con.Open( ).

    No comments

0 additional answers

Sort by: Most helpful