Number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
Assembly: System.Data (in System.Data.dll)
A batch is complete when rows have been processed or there are no more rows to send to the destination data source.
Zero (the default) indicates that each WriteToServer operation is a single batch.
If the SqlBulkCopy instance has been declared without the UseInternalTransaction option in effect, rows are sent to the server rows at a time, but no transaction-related action is taken. If UseInternalTransaction is in effect, each batch of rows is inserted as a separate transaction.
The property can be set at any time. If a bulk copy is already in progress, the current batch is sized according to the previous batch size. Subsequent batches use the new size. If the is initially zero and changed while a WriteToServer operation is already in progress, that operation loads the data as a single batch. Any subsequent WriteToServer operations on the same SqlBulkCopy instance use the new .
The following console application demonstrates how to bulk load data in batches of 50 rows. For an example illustrating how works with a transaction, see Transaction and Bulk Copy Operations.
In this example, the source data is first read from a SQL Server table to a SqlDataReader instance. The source data does not have to be located on SQL Server; you can use any data source that can be read to an IDataReader or loaded to a DataTable.
This sample will not run unless you have created the work tables as described in Bulk Copy Example Setup. 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.