DB2®BulkCopy.DB2BulkCopy(string, IBM®.Data.DB2.DB2BulkCopyOptions) Constructor
Initializes a new instance of the DB2BulkCopy class with a database connection string and DB2BulkCopyOptions enumeration values.
- Namespace:
IBM.Data.DB2- Assembly:
IBM.Data.DB2(inIBM.Data.DB2.dll)
Syntax
[Visual Basic]
Public Sub New( _
connectionString As String, _
options As DB2BulkCopyOptions _
)
[C#]
public DB2BulkCopy(
string connectionString,
DB2BulkCopyOptions options,
);
[C++]
public: DB2BulkCopy(
String* connectionString,
DB2BulkCopyOptions options,
);
[JScript]
public function DB2BulkCopy(
connectionString : String,
options : DB2BulkCopyOptions
);
Parameters
- connectionString
- The connection string for the database connection.
- options
- Options to use during the bulk copy operation. This can be specified as an individual DB2BulkCopyOptions enumeration or a bitwise mask value indicating the desired options from the DB2BulkCopyOptions enumeration.
Remarks
A DB2Connection object will be initialized using the connection string information. The DB2Connection will be opened and data will be copied to the table. The DB2Connection will be automatically closed after the bulk copy operation.
Example
[C#] The following example demonstrates a bulk copy of data from a DataTable source into the SALES table, using the TableLock and Truncate values from the DB2BulkCopyOptions enumeration. All values in the target table will be cleared before the bulk copy operation begins, and the table will be locked during the bulk copy operation.
[C#]
public static void copyIntoSales(DB2Connection connString, DataTable source)
{
DB2BulkCopy salesCopy = new DB2BulkCopy(connString,
(DB2BulkCopyOptions)DB2BulkCopyOptions.TableLock |
DB2BulkCopyOptions.Truncate);
salesCopy.DestinationTableName = "SALES";
try
{
salesCopy.WriteToServer(source);
salesCopy.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Exception");
}
}