Export (0) Print
Expand All
14 out of 22 rated this helpful - Rate this topic

OleDbDataAdapter Class

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

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

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Data.Common.DataAdapter
            System.Data.Common.DbDataAdapter
               System.Data.OleDb.OleDbDataAdapter

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

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.

Remarks

The OleDbDataAdapter serves as a bridge between a DataSet and data source for retrieving and saving data. The OleDbDataAdapter 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 OleDbDataAdapter 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 OleDbDataAdapter 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 that some OLE DB providers, including the MSDataShape provider, do not return base table or primary key information. As a result, the OleDbDataAdapter cannot properly set the PrimaryKey property on any created DataTable. In such cases you should explicitly specify primary keys for tables in the DataSet.

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

When you create an instance of OleDbDataAdapter, properties are set to their initial values. For a list of these values, see the OleDbDataAdapter constructor.

Example

[Visual Basic, C#, C++] The following example uses the OleDbCommand, OleDbDataAdapter and OleDbConnection, to select records from an Access data source, and populate a DataSet with the selected rows. The filled DataSet is then returned. To accomplish this, the method is passed an initialized DataSet, a connection string, and a query string that is an SQL SELECT statement.

[Visual Basic] 
Public Function SelectOleDbSrvRows(dataSet As DataSet, connection As String, query As String) As DataSet
    Dim conn As New OleDbConnection(connection)
    Dim adapter As New OleDbDataAdapter()
    adapter.SelectCommand = new OleDbCommand(query, conn)
    adapter.Fill(dataset)
    Return dataset
End Function

[C#] 
public DataSet SelectOleDbSrvRows(DataSet dataset,string connection,string query) 
{
    OleDbConnection conn = new OleDbConnection(connection);
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    adapter.SelectCommand = new OleDbCommand(query, conn);
    adapter.Fill(dataset);
    return dataset;
}


[C++] 
public:
DataSet* SelectOleDbSrvRows(DataSet* dataset,String* connection,String* query) 
{
    OleDbConnection* conn = new OleDbConnection(connection);
    OleDbDataAdapter* adapter = new OleDbDataAdapter();
    adapter->SelectCommand = new OleDbCommand(query, conn);
    adapter->Fill(dataset);
    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.

Requirements

Namespace: System.Data.OleDb

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

OleDbDataAdapter Members | System.Data.OleDb Namespace | OleDbConnection | OleDbCommand | DataSet | DataTable

Show:
© 2014 Microsoft. All rights reserved.