I'm using SqlBulkCopy
against two SQL Server 2008 with different sets of columns (going to move some data from prod
server to dev
). So want to skip some columns not yet existed / not yet removed.
How can I do that? Some trick with ColumnMappings
?
Edit:
I do next:
DataTable table = new DataTable();
using (var adapter = new SqlDataAdapter(sourceCommand))
{
adapter.Fill(table);
}
table.Columns
.OfType<DataColumn>()
.ForEach(c => bulk.ColumnMappings.Add(
new SqlBulkCopyColumnMapping(c.ColumnName, c.ColumnName)));
bulk.WriteToServer(table)
and get:
The given ColumnMapping does not match up with any column in the source or destination.