<PackageReference Include="System.Data.SqlClient" Version="4.7.0-preview6.19264.9" />

SqlBulkCopy

public sealed class SqlBulkCopy : IDisposable
Lets you efficiently bulk load a SQL Server table with data from another source.
public int BatchSize { get; set; }

Number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.

public int BulkCopyTimeout { get; set; }

Number of seconds for the operation to complete before it times out.

Returns a collection of SqlBulkCopyColumnMapping items. Column mappings define the relationships between columns in the data source and columns in the destination.

public string DestinationTableName { get; set; }

Name of the destination table on the server.

public bool EnableStreaming { get; set; }

Enables or disables a SqlBulkCopy object to stream data from an IDataReader object

public int NotifyAfter { get; set; }

Defines the number of rows to be processed before generating a notification event.

Occurs every time that the number of rows specified by the NotifyAfter property have been processed.

public SqlBulkCopy(SqlConnection connection)

Initializes a new instance of the SqlBulkCopy class using the specified open instance of SqlConnection.

public SqlBulkCopy(SqlConnection connection, SqlBulkCopyOptions copyOptions, SqlTransaction externalTransaction)

Initializes a new instance of the SqlBulkCopy class using the supplied existing open instance of SqlConnection. The SqlBulkCopy instance behaves according to options supplied in the copyOptionscopyOptions parameter. If a non-null SqlTransaction is supplied, the copy operations will be performed within that transaction.

public SqlBulkCopy(string connectionString)

Initializes and opens a new instance of SqlConnection based on the supplied connectionStringconnectionString. The constructor uses the SqlConnection to initialize a new instance of the SqlBulkCopy class.

public SqlBulkCopy(string connectionString, SqlBulkCopyOptions copyOptions)

Initializes and opens a new instance of SqlConnection based on the supplied connectionStringconnectionString. The constructor uses that SqlConnection to initialize a new instance of the SqlBulkCopy class. The SqlConnection instance behaves according to options supplied in the copyOptionscopyOptions parameter.

public void Close()

Closes the SqlBulkCopy instance.

public void WriteToServer(DbDataReader reader)

Copies all rows from the supplied DbDataReader array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public void WriteToServer(DataRow[] rows)

Copies all rows from the supplied DataRow array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public void WriteToServer(DataTable table)

Copies all rows in the supplied DataTable to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public void WriteToServer(DataTable table, DataRowState rowState)

Copies only rows that match the supplied row state in the supplied DataTable to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public void WriteToServer(IDataReader reader)

Copies all rows in the supplied IDataReader to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

The asynchronous version of WriteToServer, which copies all rows from the supplied DbDataReader array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public Task WriteToServerAsync(DbDataReader reader, CancellationToken cancellationToken)

The asynchronous version of WriteToServer, which copies all rows from the supplied DbDataReader array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

The asynchronous version of WriteToServer, which copies all rows from the supplied DataRow array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public Task WriteToServerAsync(DataRow[] rows, CancellationToken cancellationToken)

The asynchronous version of WriteToServer, which copies all rows from the supplied DataRow array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object. The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object.

The asynchronous version of WriteToServer, which copies all rows in the supplied DataTable to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

The asynchronous version of WriteToServer, which copies only rows that match the supplied row state in the supplied DataTable to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public Task WriteToServerAsync(DataTable table, DataRowState rowState, CancellationToken cancellationToken)

The asynchronous version of WriteToServer, which copies only rows that match the supplied row state in the supplied DataTable to a destination table specified by the DestinationTableName property of the SqlBulkCopy object. The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object.

public Task WriteToServerAsync(DataTable table, CancellationToken cancellationToken)

The asynchronous version of WriteToServer, which copies all rows in the supplied DataTable to a destination table specified by the DestinationTableName property of the SqlBulkCopy object. The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object.

The asynchronous version of WriteToServer, which copies all rows in the supplied IDataReader to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public Task WriteToServerAsync(IDataReader reader, CancellationToken cancellationToken)

The asynchronous version of WriteToServer, which copies all rows in the supplied IDataReader to a destination table specified by the DestinationTableName property of the SqlBulkCopy object. The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object.