System.Data.SqlClient.SqlBulkCopy.WriteToServer Method

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

Syntax

public void WriteToServer (System.Data.IDataReader reader)

Parameters

reader
A System.Data.IDataReader whose rows will be copied to the destination table.

Remarks

The copy operation starts at the next available row in the reader. Most of the time, the reader was just returned by erload:System.Data.IDbCommand.ExecuteReader or a similar call, so the next available row is the first row. To process multiple results, call System.Data.IDataReader.NextResult on the data reader and call SqlBulkCopy.WriteToServer(System.Data.IDataReader) again.

Note that using SqlBulkCopy.WriteToServer(System.Data.IDataReader) modifies the state of the reader. The method will call System.Data.IDataReader.Read until it returns false, the operation is aborted, or an error occurs. This means that the data reader will be in a different state, probably at the end of the result set, when the SqlBulkCopy.WriteToServer(System.Data.IDataReader) operation is complete.

While the bulk copy operation is in progress, the associated destination System.Data.SqlClient.SqlConnection is busy serving it, and no other operations can be performed on the connection.

The SqlBulkCopy.ColumnMappings collection maps from the data reader columns to the destination database table.

Requirements

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