How can I do SQL column mappings ignoring missing columns?

56 views Asked by At

I am doing bulkcopy from one table to another using the following:

bulk.DestinationTableName = reader["Tablename"].ToString();

foreach (DataColumn col in sourceTable.Columns)
{
    bulk.ColumnMappings.Add(col.ColumnName, col.ColumnName);
}

But the issue is that the first parameter, the source, has a column that is not in the destination.

How can I ignore that mapping if it doesn't exist in the destination?

I have tried checking if the column exists in the destination. But this is very slow as the source table has about 50 columns.

How can I not map the column if it's not in the destination?

0

There are 0 answers