Tehila
Tehila

Reputation: 73

how Sql bulk copy works?

I want to use SqlBulkCopy C# to insert rows to Sql DataBase but I don't understand if I define a table in the Db with X columns and I want to insert 2 DataTables- one of them contains only y/x columns and the second contains only z/x columns. when I use SqlBulkCopy, does it auto check the column name and insert value only if it is the appropriate column and null if not, or it always inserts values in the first columns and the last columns will be empty?

I tried to search it but I haven't find it? can anyone help?

Upvotes: 1

Views: 544

Answers (2)

Vicky
Vicky

Reputation: 2097

Look for :SqlBulkCopyColumnMapping

When SqlBulkCopyColumnMapping is used, only columns for which mappings are created will be copied.

If you do not create a mapping for a column, it will be ignored by the copy process.

Upvotes: 3

Kompiler
Kompiler

Reputation: 176

Take a look at the SqlBulkCopy.ColumnMappings property. It allows you to map source and destination columns when the column count or positions do not match.

Upvotes: 1

Related Questions