question

GaniTPT avatar image
0 Votes"
GaniTPT asked Viorel-1 answered

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

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)


EmpNo
Salary
Department

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

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

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.