Export (0) Print
Expand All

OleDbDataAdapter Class

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

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

public sealed class OleDbDataAdapter : DbDataAdapter, 
	IDbDataAdapter, IDataAdapter, ICloneable

The OleDbDataAdapter type exposes the following members.

  NameDescription
Public methodOleDbDataAdapter()Initializes a new instance of the OleDbDataAdapter class.
Public methodOleDbDataAdapter(OleDbCommand)Initializes a new instance of the OleDbDataAdapter class with the specified OleDbCommand as the SelectCommand property.
Public methodOleDbDataAdapter(String, OleDbConnection)Initializes a new instance of the OleDbDataAdapter class with a SelectCommand.
Public methodOleDbDataAdapter(String, String)Initializes a new instance of the OleDbDataAdapter class with a SelectCommand.
Top

  NameDescription
Public propertyAcceptChangesDuringFillGets or sets a value indicating whether AcceptChanges is called on a DataRow after it is added to the DataTable during any of the Fill operations. (Inherited from DataAdapter.)
Public propertyAcceptChangesDuringUpdateGets or sets whether AcceptChanges is called during a Update. (Inherited from DataAdapter.)
Protected propertyCanRaiseEventsGets a value indicating whether the component can raise an event. (Inherited from Component.)
Public propertyContainerGets the IContainer that contains the Component. (Inherited from Component.)
Public propertyContinueUpdateOnErrorGets or sets a value that specifies whether to generate an exception when an error is encountered during a row update. (Inherited from DataAdapter.)
Public propertyDeleteCommandGets or sets an SQL statement or stored procedure for deleting records from the data set.
Protected propertyDesignModeGets a value that indicates whether the Component is currently in design mode. (Inherited from Component.)
Protected propertyEventsGets the list of event handlers that are attached to this Component. (Inherited from Component.)
Protected propertyFillCommandBehaviorGets or sets the behavior of the command used to fill the data adapter. (Inherited from DbDataAdapter.)
Public propertyFillLoadOptionGets or sets the LoadOption that determines how the adapter fills the DataTable from the DbDataReader. (Inherited from DataAdapter.)
Public propertyInsertCommandGets or sets an SQL statement or stored procedure used to insert new records into the data source.
Public propertyMissingMappingActionDetermines the action to take when incoming data does not have a matching table or column. (Inherited from DataAdapter.)
Public propertyMissingSchemaActionDetermines the action to take when existing DataSet schema does not match incoming data. (Inherited from DataAdapter.)
Public propertyReturnProviderSpecificTypesGets or sets whether the Fill method should return provider-specific values or common CLS-compliant values. (Inherited from DataAdapter.)
Public propertySelectCommandGets or sets an SQL statement or stored procedure used to select records in the data source.
Public propertySiteGets or sets the ISite of the Component. (Inherited from Component.)
Public propertyTableMappingsGets a collection that provides the master mapping between a source table and a DataTable. (Inherited from DataAdapter.)
Public propertyUpdateBatchSizeGets or sets a value that enables or disables batch processing support, and specifies the number of commands that can be executed in a batch. (Inherited from DbDataAdapter.)
Public propertyUpdateCommandGets or sets an SQL statement or stored procedure used to update records in the data source.
Top

  NameDescription
Protected methodAddToBatchAdds a IDbCommand to the current batch. (Inherited from DbDataAdapter.)
Protected methodClearBatchRemoves all IDbCommand objects from the batch. (Inherited from DbDataAdapter.)
Protected methodCloneInternals Obsolete. Creates a copy of this instance of DataAdapter. (Inherited from DataAdapter.)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Protected methodCreateRowUpdatedEventInitializes a new instance of the RowUpdatedEventArgs class. (Inherited from DbDataAdapter.)
Protected methodCreateRowUpdatingEventInitializes a new instance of the RowUpdatingEventArgs class. (Inherited from DbDataAdapter.)
Protected methodCreateTableMappingsCreates a new DataTableMappingCollection. (Inherited from DataAdapter.)
Public methodDispose()Releases all resources used by the Component. (Inherited from Component.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the DbDataAdapter and optionally releases the managed resources. (Inherited from DbDataAdapter.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodExecuteBatchExecutes the current batch. (Inherited from DbDataAdapter.)
Public methodFill(DataSet)Adds or refreshes rows in the DataSet. (Inherited from DbDataAdapter.)
Public methodFill(DataTable)Adds or refreshes rows in a specified range in the DataSet to match those in the data source using the DataTable name. (Inherited from DbDataAdapter.)
Public methodFill(DataSet, String)Adds or refreshes rows in the DataSet to match those in the data source using the DataSet and DataTable names. (Inherited from DbDataAdapter.)
Protected methodFill(DataTable, IDataReader)Adds or refreshes rows in the DataTable to match those in the data source using the DataTable name and the specified IDataReader. (Inherited from DataAdapter.)
Public methodFill(DataTable, Object)Adds or refreshes rows in a DataTable to match those in an ADO Recordset or Record object using the specified DataTable and ADO objects.
Public methodFill(DataSet, Object, String)Adds or refreshes rows in the DataSet to match those in an ADO Recordset or Record object using the specified DataSet, ADO object, and source table name.
Protected methodFill(DataTable, IDbCommand, CommandBehavior)Adds or refreshes rows in a DataTable to match those in the data source using the specified DataTable, IDbCommand and CommandBehavior. (Inherited from DbDataAdapter.)
Public methodFill(Int32, Int32, DataTable[])Adds or refreshes rows in a DataTable to match those in the data source starting at the specified record and retrieving up to the specified maximum number of records. (Inherited from DbDataAdapter.)
Public methodFill(DataSet, Int32, Int32, String)Adds or refreshes rows in a specified range in the DataSet to match those in the data source using the DataSet and DataTable names. (Inherited from DbDataAdapter.)
Protected methodFill(DataTable[], IDataReader, Int32, Int32)Adds or refreshes rows in a specified range in the collection of DataTable objects to match those in the data source. (Inherited from DataAdapter.)
Protected methodFill(DataSet, String, IDataReader, Int32, Int32)Adds or refreshes rows in a specified range in the DataSet to match those in the data source using the DataSet and DataTable names. (Inherited from DataAdapter.)
Protected methodFill(DataTable[], Int32, Int32, IDbCommand, CommandBehavior)Adds or refreshes rows in a specified range in the DataSet to match those in the data source using the DataSet and DataTable names. (Inherited from DbDataAdapter.)
Protected methodFill(DataSet, Int32, Int32, String, IDbCommand, CommandBehavior)Adds or refreshes rows in a specified range in the DataSet to match those in the data source using the DataSet and source table names, command string, and command behavior. (Inherited from DbDataAdapter.)
Public methodFillSchema(DataSet, SchemaType)Adds a DataTable named "Table" to the specified DataSet and configures the schema to match that in the data source based on the specified SchemaType. (Inherited from DbDataAdapter.)
Public methodFillSchema(DataTable, SchemaType)Configures the schema of the specified DataTable based on the specified SchemaType. (Inherited from DbDataAdapter.)
Public methodFillSchema(DataSet, SchemaType, String)Adds a DataTable to the specified DataSet and configures the schema to match that in the data source based upon the specified SchemaType and DataTable. (Inherited from DbDataAdapter.)
Protected methodFillSchema(DataTable, SchemaType, IDataReader)Adds a DataTable to the specified DataSet. (Inherited from DataAdapter.)
Protected methodFillSchema(DataSet, SchemaType, String, IDataReader)Adds a DataTable to the specified DataSet. (Inherited from DataAdapter.)
Protected methodFillSchema(DataTable, SchemaType, IDbCommand, CommandBehavior)Configures the schema of the specified DataTable based on the specified SchemaType, command string, and CommandBehavior values. (Inherited from DbDataAdapter.)
Protected methodFillSchema(DataSet, SchemaType, IDbCommand, String, CommandBehavior)Adds a DataTable to the specified DataSet and configures the schema to match that in the data source based on the specified SchemaType. (Inherited from DbDataAdapter.)
Protected methodFinalizeReleases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.)
Protected methodGetBatchedParameterReturns a IDataParameter from one of the commands in the current batch. (Inherited from DbDataAdapter.)
Protected methodGetBatchedRecordsAffectedReturns information about an individual update attempt within a larger batched update. (Inherited from DbDataAdapter.)
Public methodGetFillParametersGets the parameters set by the user when executing an SQL SELECT statement. (Inherited from DbDataAdapter.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodGetServiceReturns an object that represents a service provided by the Component or by its Container. (Inherited from Component.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodHasTableMappingsIndicates whether a DataTableMappingCollection has been created. (Inherited from DataAdapter.)
Protected methodInitializeBatchingInitializes batching for the DbDataAdapter. (Inherited from DbDataAdapter.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected methodOnFillErrorInvoked when an error occurs during a Fill. (Inherited from DataAdapter.)
Protected methodOnRowUpdatedRaises the RowUpdated event of a .NET Framework data provider. (Inherited from DbDataAdapter.)
Protected methodOnRowUpdatingRaises the RowUpdating event of a .NET Framework data provider. (Inherited from DbDataAdapter.)
Public methodResetFillLoadOptionResets FillLoadOption to its default state and causes DataAdapter.Fill to honor AcceptChangesDuringFill. (Inherited from DataAdapter.)
Public methodShouldSerializeAcceptChangesDuringFillDetermines whether the AcceptChangesDuringFill property should be persisted. (Inherited from DataAdapter.)
Public methodShouldSerializeFillLoadOptionDetermines whether the FillLoadOption property should be persisted. (Inherited from DataAdapter.)
Protected methodShouldSerializeTableMappingsDetermines whether one or more DataTableMapping objects exist and they should be persisted. (Inherited from DataAdapter.)
Protected methodTerminateBatchingEnds batching for the DbDataAdapter. (Inherited from DbDataAdapter.)
Public methodToStringReturns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.)
Public methodUpdate(DataRow[])Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified array of DataRow objects. (Inherited from DbDataAdapter.)
Public methodUpdate(DataSet)Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified DataSet. (Inherited from DbDataAdapter.)
Public methodUpdate(DataTable)Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified DataTable. (Inherited from DbDataAdapter.)
Protected methodUpdate(DataRow[], DataTableMapping)Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified array of DataRow objects. (Inherited from DbDataAdapter.)
Public methodUpdate(DataSet, String)Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the DataSet with the specified DataTable name. (Inherited from DbDataAdapter.)
Top

  NameDescription
Public eventDisposedOccurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)
Public eventFillErrorReturned when an error occurs during a fill operation. (Inherited from DataAdapter.)
Public eventRowUpdatedOccurs during Update after a command is executed against the data source. The attempt to update is made. Therefore, the event occurs.
Public eventRowUpdatingOccurs during Update before a command is executed against the data source. The attempt to update is made. Therefore, the event occurs.
Top

  NameDescription
Explicit interface implemetationPrivate methodICloneable.CloneFor a description of this member, see ICloneable.Clone.
Explicit interface implemetationPrivate propertyIDataAdapter.TableMappingsIndicates how a source table is mapped to a dataset table. (Inherited from DataAdapter.)
Explicit interface implemetationPrivate propertyIDbDataAdapter.DeleteCommandFor a description of this member, see DeleteCommand().
Explicit interface implemetationPrivate propertyIDbDataAdapter.InsertCommandFor a description of this member, see InsertCommand().
Explicit interface implemetationPrivate propertyIDbDataAdapter.SelectCommandFor a description of this member, see SelectCommand().
Explicit interface implemetationPrivate propertyIDbDataAdapter.UpdateCommandFor a description of this member, see UpdateCommand().
Top

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 appropriate 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 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 (ADO.NET).

Note that some OLE DB providers, including the MSDataShape provider, do not return base table or primary key information. Therefore, the OleDbDataAdapter cannot correctly set the PrimaryKey property on any created DataTable. In these 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.

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.


public static OleDbDataAdapter CreateDataAdapter(string selectCommand,
    OleDbConnection connection)
{
    OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand, connection);

    adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

    // Create the Insert, Update and Delete commands.
    adapter.InsertCommand = new OleDbCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)");

    adapter.UpdateCommand = new OleDbCommand(
        "UPDATE Customers SET CustomerID = ?, CompanyName = ? " +
        "WHERE CustomerID = ?");

    adapter.DeleteCommand = new OleDbCommand(
        "DELETE FROM Customers WHERE CustomerID = ?");

    // Create the parameters.
    adapter.InsertCommand.Parameters.Add("@CustomerID", 
        OleDbType.Char, 5, "CustomerID");
    adapter.InsertCommand.Parameters.Add("@CompanyName", 
        OleDbType.VarChar, 40, "CompanyName");

    adapter.UpdateCommand.Parameters.Add("@CustomerID", 
        OleDbType.Char, 5, "CustomerID");
    adapter.UpdateCommand.Parameters.Add("@CompanyName", 
        OleDbType.VarChar, 40, "CompanyName");
    adapter.UpdateCommand.Parameters.Add("@oldCustomerID", 
        OleDbType.Char, 5, "CustomerID").SourceVersion = 
        DataRowVersion.Original;

    adapter.DeleteCommand.Parameters.Add("@CustomerID", 
        OleDbType.Char, 5, "CustomerID").SourceVersion = 
        DataRowVersion.Original;

    return adapter;
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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

Community Additions

ADD
Show:
© 2014 Microsoft