OdbcDataAdapter Class

Represents a set of data commands and a connection to a data source that are used to fill the DataSet and update the data source. This class cannot be inherited.

Namespace: System.Data.Odbc
Assembly: System.Data (in system.data.dll)

Public NotInheritable Class OdbcDataAdapter
	Inherits DbDataAdapter
	Implements IDbDataAdapter, IDataAdapter, ICloneable
Dim instance As OdbcDataAdapter

public final class OdbcDataAdapter extends DbDataAdapter implements IDbDataAdapter, IDataAdapter, 
public final class OdbcDataAdapter extends DbDataAdapter implements IDbDataAdapter, IDataAdapter, 
Not applicable.

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

When the OdbcDataAdapter fills a DataSet, it creates the required tables and columns for the returned data if they do not already exist. However, primary key information is not included in the implicitly created schema unless the MissingSchemaAction property is set to AddWithKey. You may also have the OdbcDataAdapter create the schema of the DataSet, including primary key information, before filling it with data using FillSchema. For more information, see Adding Existing Constraints to a DataSet.


When you call the Fill method on a data source that does not have a primary key column, the OdbcDataAdapter tries to promote the unique constraint column to the primary key. In the process, the OdbcDataAdapter 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.


Due to the limitations of native ODBC drivers, only one DataTable is ever returned when you call FillSchema. This is true even when executing SQL batch statements from which multiple DataTable objects would be expected.

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

The following example uses OdbcCommand, OdbcDataAdapter, and OdbcConnection to select records and populate a DataSet with the selected rows.

Public Function GetDataSetFromAdapter( _
    ByVal dataSet As DataSet, ByVal connectionString As String, _
    ByVal queryString As String) As DataSet

    Using connection As New OdbcConnection(connectionString)
        Dim adapter As New OdbcDataAdapter(queryString, connection)

        ' Open the connection and fill the DataSet.
        Catch ex As Exception
        End Try
        ' The connection is automatically closed when the
        ' code exits the Using block.
    End Using

    Return dataSet
End Function


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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1

Community Additions