DB2®BulkCopyColumnMappingCollection.Clear Method

Clears the current collection of DB2BulkCopyColumnMapping objects.

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

Syntax


[Visual Basic]
Public Sub Clear
[C#]
public void Clear ()
[C++]
public:
void Clear ()
[JScript]
public function Clear ()

Remarks

If you need to perform multiple bulk copies, it would be more efficient to use a single DB2BulkCopy instance than to create a new instance for each bulk copy operation. When performing multiple bulk copy operations, use the Clear method to remove the existing column mappings (after running the DB2BulkCopy.WriteToServer method for the previous operation) before defining new column mappings for the next bulk copy operation.

Example

[C#] The following example demonstrates a method that accepts existing DB2BulkCopy and DB2BulkCopyColumnMappingCollection instances and performs bulk copy of data from a DB2DataReader into the DEPARTMENT table. Other methods similar to this one could reuse the DB2BulkCopy and DB2BulkCopyColumnMappingCollection instances, providing they Clear the column mappings before defining their own.

[C#]
public static void copyDept(DB2Connection conn, DB2DataReader reader,
                            DB2BulkCopy salesCopy,
                            DB2BulkCopyColumnMappingCollection colMapCollection)
{
  colMapCollection.Clear();
  salesCopy.DestinationTableName = "DEPARTMENT";

  colMapCollection.Add("DEPTNUMB", "DEPTNO");
  colMapCollection.Add("DEPTNAME", "DEPTNAME");
  colMapCollection.Add("MANAGER", "ADMRDEPT");
  colMapCollection.Add("LOCATION", "LOCATION");

  try
  {
    salesCopy.WriteToServer(reader);
    colMapCollection.Clear();
  }
  catch (DB2Exception ex)
  {
    MessageBox.Show(ex.ToString(), "Exception");
  }
}