Export (0) Print
Expand All

OdbcDataAdapter Class

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

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.

For a list of all members of this type, see OdbcDataAdapter Members.


[Visual Basic]
NotInheritable Public Class OdbcDataAdapter
   Inherits DbDataAdapter
   Implements IDbDataAdapter
public sealed class OdbcDataAdapter : DbDataAdapter, IDbDataAdapter
public __gc __sealed class OdbcDataAdapter : public DbDataAdapter,
public class OdbcDataAdapter extends DbDataAdapter implements

Thread Safety

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


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 will create the necessary tables and columns for the returned data if they do not already exist. However, primary key information will not be 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.

Note   When you call the Fill method on a data source that does not have a primary key column, the OdbcDataAdapter attempts 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.
Note   Due to the limitations of native ODBC drivers, only one DataTable is ever returned when you call DbDataAdapter.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.


[Visual Basic, C#, C++] The following example uses OdbcCommand, OdbcDataAdapter and OdbcConnection 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 data source.

[Visual Basic] 
Public Function SelectOdbcSrvRows(dataSet As DataSet, connection As String, query As String) As DataSet
    Dim conn As New OdbcConnection(connection)
    Dim adapter As New OdbcDataAdapter()
    adapter.SelectCommand = new OdbcCommand(query, conn)
    Return dataset
End Function

public DataSet SelectOdbcSrvRows(DataSet dataset,string connection,string query) 
    OdbcConnection conn = new OdbcConnection(connection);
    OdbcDataAdapter adapter = new OdbcDataAdapter();
    adapter.SelectCommand = new OdbcCommand(query, conn);
    return dataset;

    DataSet* SelectOdbcSrvRows(DataSet* dataset, String* connection, String* query)
        OdbcConnection* conn = new OdbcConnection(connection);
        OdbcDataAdapter* adapter = new OdbcDataAdapter();
        adapter->SelectCommand = new OdbcCommand(query, conn);
        return dataset;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Data.Odbc

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Data (in System.Data.dll)

See Also

OdbcDataAdapter Members | System.Data.Odbc Namespace | OdbcConnection | OdbcCommand | DataSet | DataTable

© 2015 Microsoft