SqlBulkCopy::WriteToServer Method (array<DataRow^>^)

 

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

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

public:
void WriteToServer(
	array<DataRow^>^ rows
)

Parameters

rows
Type: array<System.Data::DataRow^>^

An array of DataRow objects that will be copied to the destination table.

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

The ColumnMappings collection maps from the DataRow columns to the destination database table.

The following console application demonstrates how to bulk load data from a DataRow array. The destination table is a table in the AdventureWorks database.

In this example, a DataTable is created at run time. A single row is selected from the DataTable to copy to the destination table.

System_CAPS_importantImportant

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.

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

.NET Framework
Available since 2.0
Return to top
Show: