MySqlDataAdapter Class

MySQL Connector/Net

MySqlDataAdapter Class
Represents a set of data commands and a database connection that are used to fill a dataset and update a MySQL database. This class cannot be inherited.
Inheritance Hierarchy
SystemObject  SystemMarshalByRefObject
    System.ComponentModelComponent
      System.Data.CommonDataAdapter
        System.Data.CommonDbDataAdapter
          MySql.Data.MySqlClientMySqlDataAdapter

Namespace: MySql.Data.MySqlClient
Assembly: MySql.Data (in MySql.Data.dll) Version: 6.9.9
Syntax
public sealed class MySqlDataAdapter : DbDataAdapter, 
	IDbDataAdapter, IDataAdapter, ICloneable
Public NotInheritable Class MySqlDataAdapter
	Inherits DbDataAdapter
	Implements IDbDataAdapter, IDataAdapter, ICloneable
public ref class MySqlDataAdapter sealed : public DbDataAdapter, 
	IDbDataAdapter, IDataAdapter, ICloneable
[<SealedAttribute>]
type MySqlDataAdapter =  
    class
        inherit DbDataAdapter
        interface IDbDataAdapter
        interface IDataAdapter
        interface ICloneable
    end

The MySqlDataAdapter type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleMySqlDataAdapter
Initializes a new instance of the MySqlDataAdapter class.
Public methodCode exampleMySqlDataAdapter(MySqlCommand)
Initializes a new instance of the MySqlDataAdapter class with the specified MySqlCommand as the SelectCommand property.
Public methodCode exampleMySqlDataAdapter(String, MySqlConnection)
Initializes a new instance of the MySqlDataAdapter class with a SelectCommand and a MySqlConnection object.
Public methodCode exampleMySqlDataAdapter(String, String)
Initializes a new instance of the MySqlDataAdapter class with a SelectCommand and a connection string.
Top
Properties
  NameDescription
Public propertyAcceptChangesDuringFill
Gets 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 propertyAcceptChangesDuringUpdate
Gets or sets whether AcceptChanges is called during a Update(DataSet).
(Inherited from DataAdapter.)
Protected propertyCanRaiseEvents
Gets a value indicating whether the component can raise an event.
(Inherited from Component.)
Public propertyContainer
Gets the IContainer that contains the Component.
(Inherited from Component.)
Public propertyContinueUpdateOnError
Gets or sets a value that specifies whether to generate an exception when an error is encountered during a row update.
(Inherited from DataAdapter.)
Public propertyCode exampleDeleteCommand
Gets or sets a SQL statement or stored procedure used to delete records from the data set.
Protected propertyDesignMode
Gets a value that indicates whether the Component is currently in design mode.
(Inherited from Component.)
Protected propertyEvents
Gets the list of event handlers that are attached to this Component.
(Inherited from Component.)
Protected propertyFillCommandBehavior
Gets or sets the behavior of the command used to fill the data adapter.
(Inherited from DbDataAdapter.)
Public propertyFillLoadOption
Gets or sets the LoadOption that determines how the adapter fills the DataTable from the DbDataReader.
(Inherited from DataAdapter.)
Public propertyCode exampleInsertCommand
Gets or sets a SQL statement or stored procedure used to insert records into the data set.
Public propertyMissingMappingAction
Determines the action to take when incoming data does not have a matching table or column.
(Inherited from DataAdapter.)
Public propertyMissingSchemaAction
Determines the action to take when existing DataSet schema does not match incoming data.
(Inherited from DataAdapter.)
Public propertyReturnProviderSpecificTypes
Gets or sets whether the Fill method should return provider-specific values or common CLS-compliant values.
(Inherited from DataAdapter.)
Public propertyCode exampleSelectCommand
Gets or sets a SQL statement or stored procedure used to select records in the data source.
Public propertySite
Gets or sets the ISite of the Component.
(Inherited from Component.)
Public propertyTableMappings
Gets a collection that provides the master mapping between a source table and a DataTable.
(Inherited from DataAdapter.)
Public propertyUpdateBatchSize (Overrides DbDataAdapterUpdateBatchSize.)
Public propertyCode exampleUpdateCommand
Gets or sets a SQL statement or stored procedure used to updated records in the data source.
Top
Methods
  NameDescription
Protected methodAddToBatch (Overrides DbDataAdapterAddToBatch(IDbCommand).)
Protected methodClearBatch (Overrides DbDataAdapterClearBatch.)
Protected methodCloneInternals Obsolete.
Creates a copy of this instance of DataAdapter.
(Inherited from DataAdapter.)
Public methodCreateObjRef
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject.)
Protected methodCreateRowUpdatedEvent (Overrides DbDataAdapterCreateRowUpdatedEvent(DataRow, IDbCommand, StatementType, DataTableMapping).)
Protected methodCreateRowUpdatingEvent (Overrides DbDataAdapterCreateRowUpdatingEvent(DataRow, IDbCommand, StatementType, DataTableMapping).)
Protected methodCreateTableMappings (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
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodExecuteBatch (Overrides DbDataAdapterExecuteBatch.)
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(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.)
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(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(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, 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(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 methodFillAsync(DataSet)
Async version of Fill
Public methodFillAsync(DataTable)
Async version of Fill
Public methodFillAsync(DataSet, String)
Async version of Fill
Public methodFillAsync(DataSet, CancellationToken)
Public methodFillAsync(DataTable, IDataReader)
Async version of Fill
Public methodFillAsync(DataTable, CancellationToken)
Public methodFillAsync(DataSet, String, CancellationToken)
Public methodFillAsync(DataTable, IDataReader, CancellationToken)
Public methodFillAsync(DataTable, IDbCommand, CommandBehavior)
Async version of Fill
Public methodFillAsync(Int32, Int32, DataTable)
Async version of Fill
Public methodFillAsync(DataSet, Int32, Int32, String)
Async version of Fill
Public methodFillAsync(DataTable, IDbCommand, CommandBehavior, CancellationToken)
Public methodFillAsync(Int32, Int32, CancellationToken, DataTable)
Public methodFillAsync(DataSet, Int32, Int32, String, CancellationToken)
Public methodFillAsync(DataSet, String, IDataReader, Int32, Int32)
Async version of Fill
Public methodFillAsync(DataTable, Int32, Int32, IDbCommand, CommandBehavior)
Async version of Fill
Public methodFillAsync(DataSet, Int32, Int32, String, IDbCommand, CommandBehavior)
Async version of Fill
Public methodFillAsync(DataSet, String, IDataReader, Int32, Int32, CancellationToken)
Public methodFillAsync(DataTable, Int32, Int32, IDbCommand, CommandBehavior, CancellationToken)
Public methodFillAsync(DataSet, Int32, Int32, String, IDbCommand, CommandBehavior, CancellationToken)
Public methodFillSchema(DataTable, SchemaType)
Configures the schema of the specified DataTable based on the specified SchemaType.
(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(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(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, String, IDataReader)
Adds a DataTable to the specified DataSet.
(Inherited from DataAdapter.)
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.)
Public methodFillSchemaAsync(DataSet, SchemaType)
Async version of FillSchema
Public methodFillSchemaAsync(DataTable, SchemaType)
Async version of FillSchema
Public methodFillSchemaAsync(DataSet, SchemaType, String)
Async version of FillSchema
Public methodFillSchemaAsync(DataSet, SchemaType, CancellationToken)
Public methodFillSchemaAsync(DataTable, SchemaType, IDataReader)
Async version of FillSchema
Public methodFillSchemaAsync(DataTable, SchemaType, CancellationToken)
Public methodFillSchemaAsync(DataSet, SchemaType, String, IDataReader)
Async version of FillSchema
Public methodFillSchemaAsync(DataSet, SchemaType, String, CancellationToken)
Public methodFillSchemaAsync(DataTable, SchemaType, IDataReader, CancellationToken)
Public methodFillSchemaAsync(DataTable, SchemaType, IDbCommand, CommandBehavior)
Async version of FillSchema
Public methodFillSchemaAsync(DataSet, SchemaType, IDbCommand, String, CommandBehavior)
Async version of FillSchema
Public methodFillSchemaAsync(DataSet, SchemaType, String, IDataReader, CancellationToken)
Public methodFillSchemaAsync(DataTable, SchemaType, IDbCommand, CommandBehavior, CancellationToken)
Public methodFillSchemaAsync(DataSet, SchemaType, IDbCommand, String, CommandBehavior, CancellationToken)
Protected methodFinalize
Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection.
(Inherited from Component.)
Protected methodGetBatchedParameter (Overrides DbDataAdapterGetBatchedParameter(Int32, Int32).)
Protected methodGetBatchedRecordsAffected
Returns information about an individual update attempt within a larger batched update.
(Inherited from DbDataAdapter.)
Public methodGetFillParameters
Gets the parameters set by the user when executing an SQL SELECT statement.
(Inherited from DbDataAdapter.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetLifetimeService
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Protected methodGetService
Returns an object that represents a service provided by the Component or by its Container.
(Inherited from Component.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodHasTableMappings
Indicates whether a DataTableMappingCollection has been created.
(Inherited from DataAdapter.)
Protected methodInitializeBatching (Overrides DbDataAdapterInitializeBatching.)
Public methodInitializeLifetimeService
Obtains 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 methodOnFillError
Invoked when an error occurs during a Fill.
(Inherited from DataAdapter.)
Protected methodOnRowUpdated
Overridden. Raises the RowUpdated event.
(Overrides DbDataAdapterOnRowUpdated(RowUpdatedEventArgs).)
Protected methodOnRowUpdating
Overridden. Raises the RowUpdating event.
(Overrides DbDataAdapterOnRowUpdating(RowUpdatingEventArgs).)
Public methodResetFillLoadOption
Resets FillLoadOption to its default state and causes Fill(DataSet) to honor AcceptChangesDuringFill.
(Inherited from DataAdapter.)
Public methodShouldSerializeAcceptChangesDuringFill
Determines whether the AcceptChangesDuringFill property should be persisted.
(Inherited from DataAdapter.)
Public methodShouldSerializeFillLoadOption
Determines whether the FillLoadOption property should be persisted.
(Inherited from DataAdapter.)
Protected methodShouldSerializeTableMappings
Determines whether one or more DataTableMapping objects exist and they should be persisted.
(Inherited from DataAdapter.)
Protected methodTerminateBatching (Overrides DbDataAdapterTerminateBatching.)
Public methodToString
Returns a String containing the name of the Component, if any. This method should not be overridden.
(Inherited from Component.)
Public methodUpdate(DataSet)
Updates the values in the database by executing the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified DataSet.
(Inherited from DbDataAdapter.)
Public methodUpdate(DataRow)
Updates the values in the database by executing the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified array in the DataSet.
(Inherited from DbDataAdapter.)
Public methodUpdate(DataTable)
Updates the values in the database by executing the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the specified DataTable.
(Inherited from DbDataAdapter.)
Public methodUpdate(DataSet, String)
Updates the values in the database by executing 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.)
Protected methodUpdate(DataRow, DataTableMapping) (Overrides DbDataAdapterUpdate(DataRow, DataTableMapping).)
Public methodUpdateAsync(DataRow)
Async version of Update
Public methodUpdateAsync(DataSet)
Async version of Update
Public methodUpdateAsync(DataTable)
Async version of Update
Public methodUpdateAsync(DataRow, DataTableMapping)
Async version of Update
Public methodUpdateAsync(DataRow, CancellationToken)
Public methodUpdateAsync(DataSet, String)
Async version of Update
Public methodUpdateAsync(DataSet, CancellationToken)
Public methodUpdateAsync(DataTable, CancellationToken)
Public methodUpdateAsync(DataRow, DataTableMapping, CancellationToken)
Public methodUpdateAsync(DataSet, String, CancellationToken)
Top
Events
  NameDescription
Public eventDisposed
Occurs when the component is disposed by a call to the Dispose method.
(Inherited from Component.)
Public eventFillError
Returned when an error occurs during a fill operation.
(Inherited from DataAdapter.)
Public eventRowUpdated
Occurs during Update after a command is executed against the data source. The attempt to update is made, so the event fires.
Public eventRowUpdating
Occurs during Update before a command is executed against the data source. The attempt to update is made, so the event fires.
Top
Remarks

The MySQLDataAdapter, serves as a bridge between a DataSet and MySQL for retrieving and saving data. The MySQLDataAdapter provides this bridge by mapping Fill(DataSet), which changes the data in the DataSet to match the data in the data source, and Update(DataSet), which changes the data in the data source to match the data in the DataSet, using the appropriate SQL statements against the data source.

When the MySQLDataAdapter 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 MySQLDataAdapter create the schema of the DataSet, including primary key information, before filling it with data using FillSchema(DataTable, SchemaType).

MySQLDataAdapter is used in conjunction with MySqlConnection and MySqlCommand to increase performance when connecting to a MySQL database.

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

When an instance of MySQLDataAdapter is created, the read/write properties are set to initial values. For a list of these values, see the MySQLDataAdapter constructor.

Note Note
Please be aware that the DataColumn class allows only Int16, Int32, and Int64 to have the AutoIncrement property set. If you plan to use autoincremement columns with MySQL, you should consider using signed integer columns.
Examples
The following example creates a MySqlCommand and a MySqlConnection. The MySqlConnection is opened and set as the Connection for the MySqlCommand. The example then calls ExecuteNonQuery, and closes the connection. To accomplish this, the ExecuteNonQuery is passed a connection string and a query string that is a SQL INSERT statement.
public DataSet SelectRows(DataSet dataset,string connection,string query)
{
MySqlConnection conn = new MySqlConnection(connection);
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = new MySqlCommand(query, conn);
adapter.Fill(dataset);
return dataset;
}
Public Function SelectRows(dataSet As DataSet, connection As String, query As String) As DataSet
Dim conn As New MySqlConnection(connection)
Dim adapter As New MySqlDataAdapter()
adapter.SelectCommand = new MySqlCommand(query, conn)
adapter.Fill(dataset)
Return dataset
End Function

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also