DB2 Version 9.7 for Linux, UNIX, and Windows

DB2BulkCopy Class

Facilitates the copying of rows from a data source to a table in a database.

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Inheritance hierarchy

System.Object
   System.MarshalByRefObject
      IBM.Data.DB2.DB2BulkCopy

Syntax

[Visual Basic]
NotInheritable Public Class DB2BulkCopy
[C#]
public sealed class DB2BulkCopy
[C++]
public ref class DB2BulkCopy sealed
[JScript]
public final class DB2BulkCopy

Remarks

The source of the data can be DataRow, DataTable, or DataReader objects, which means that data to be copied can come from any source that is readable by your application. A value is generated automatically for such source of data using the GENERATED ALWAYS AS statement.The destination is a table in a database.

To enable the copying of data from columns that have names different from the destination table, DB2BulkCopy uses DB2CopyColumnMapping and DB2CopyColumnMappingCollection objects.

Example

[C#] The following example demonstrates a bulk copy of data from a DataTable source into the SALES table.

[C#]
public static void copyIntoSales(DB2Connection conn, DataTable source)
{
  DB2BulkCopy salesCopy = new DB2BulkCopy(conn);
  salesCopy.DestinationTableName = "SALES";

  try
  {
    salesCopy.WriteToServer(source);
    salesCopy.Close();
  }
  catch (Exception ex)
  {
    MessageBox.Show(ex.ToString(), "Exception");
  }
}

Thread safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

Version information

Last update
This topic was last updated for: IBM DB2 Version 9.7
.NET Framework version
Supported in: 2.0, 3.0, 3.5 and 4.0
IBM Data Server Client
Supported in: IBM® DB2® Version 9 through Version 9.7