Export (0) Print
Expand All

SqlBulkCopyOptions Enumeration

Bitwise flag that specifies one or more options to use with an instance of SqlBulkCopy.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

public enum SqlBulkCopyOptions

Member nameDescription
DefaultUse the default values for all options.
KeepIdentityPreserve source identity values. When not specified, identity values are assigned by the destination.
CheckConstraintsCheck constraints while data is being inserted. By default, constraints are not checked.
TableLockObtain a bulk update lock for the duration of the bulk copy operation. When not specified, row locks are used.
KeepNullsPreserve null values in the destination table regardless of the settings for default values. When not specified, null values are replaced by default values where applicable.
FireTriggersWhen specified, cause the server to fire the insert triggers for the rows being inserted into the database.
UseInternalTransactionWhen specified, each batch of the bulk-copy operation will occur within a transaction. If you indicate this option and also provide a SqlTransaction object to the constructor, an ArgumentException occurs.

You can use the SqlBulkCopyOptions enumeration when you construct a SqlBulkCopy instance to change how the WriteToServer methods for that instance behave.

The following console application demonstrates how to perform a bulk load that copies the value in the identity column of the source table to the corresponding column in the destination table, instead of generating a new value for each row's identity column.

To see how the option changes the way the bulk load works, run the sample with the dbo.BulkCopyDemoMatchingColumns table empty. All rows load from the source. Next, run the sample again without emptying the table. An exception is thrown, and the code writes a message to the console window notifying you that rows were not added because of primary key violations.

Important noteImportant Note:

This sample will not run unless you have created the work tables as described in Bulk Copy Example Setup (ADO.NET). This code is provided to demonstrate the syntax for using SqlBulkCopy only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL INSERT … SELECT statement to copy the data.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft