DB2 Version 10.1 for Linux, UNIX, and Windows

DB2DataAdapter Class

Represents a set of data commands and a connection to a database that are used to fill the DataSet and update the database.

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

Inheritance hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Data.Common.DataAdapter
            System.Data.Common.DbDataAdapter
               IBM.Data.DB2.DB2DataAdapter

Syntax

[Visual Basic]
NotInheritable Public Class DB2DataAdapter
   Inherits DbDataAdapter
   Implements IDbDataAdapter
[C#]
public sealed class DB2DataAdapter : DbDataAdapter, IDbDataAdapter
[C++]
public __gc __sealed class DB2DataAdapter : public DbDataAdapter,
   IDbDataAdapter
[JScript]
public class DB2DataAdapter extends DbDataAdapter implements
   IDbDataAdapter

Remarks

The DB2DataAdapter serves as a bridge between a DataSet and database for retrieving and saving data. The DB2DataAdapter provides this bridge by using Fill to load data from the database into the DataSet, and using Update to send changes made in the DataSet back to the database.

Note: When you call the Fill method on a database that does not have a primary key column, the DB2DataAdapter attempts to promote the unique constraint column to the primary key. In the process, the DB2DataAdapter marks the unique constraint as not nullable. This behavior works unless there is a null value in the unique constraint column. If there is a null value, the Fill method fails with a constraint violation. To avoid this situation, do not allow null values in the unique constraint column.

The DB2DataAdapter also includes the SelectCommand, InsertCommand, DeleteCommand, UpdateCommand, and TableMappings properties to facilitate loading and updating of data.

Example

[Visual Basic, C#] The following example uses DB2Command , DB2DataAdapter and DB2Connection to select records, and populate a DataSet with the selected rows. The filled DataSet is then returned. To accomplish this, the method is passed an initialized DataSet, with the SelectCommand set with the specified SQL SELECT statement and a connection to the database.

[Visual Basic]
Public Function SelectDB2SrvRows(dataSet As DataSet, 
    connection As String, query As String) As DataSet
    Dim conn As New DB2Connection(connection)
    Dim adapter As New DB2DataAdapter()
    adapter.SelectCommand = new DB2Command(query, conn)
    adapter.Fill(dataset)
    Return dataset
End Function
[C#]
public DataSet SelectDB2SrvRows(DataSet dataset,string connection,string query)
{
    DB2Connection conn = new DB2Connection(connection);
    DB2DataAdapter adapter = new DB2DataAdapter();
    adapter.SelectCommand = new DB2Command(query, conn);
    adapter.Fill(dataset);
    return dataset;
}

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.5
.NET Framework version
Supported in: 2.0, 3.0, 3.5, and 4.0
IBM Data Server Client
Supported in: 8.1.2 and up