MySqlCommandBuilder Class |

System.ComponentModelComponent
System.Data.CommonDbCommandBuilder
MySql.Data.MySqlClientMySqlCommandBuilder
Namespace: MySql.Data.MySqlClient
Assembly: MySql.Data (in MySql.Data.dll) Version: 6.9.9

The MySqlCommandBuilder type exposes the following members.

Name | Description | |
---|---|---|
![]() | MySqlCommandBuilder |
Initializes a new instance of the MySqlCommandBuilder class.
|
![]() | MySqlCommandBuilder(MySqlDataAdapter) |
Initializes a new instance of the MySqlCommandBuilder class
with the associated MySqlDataAdapter object.
|

Name | Description | |
---|---|---|
![]() | CanRaiseEvents | Gets a value indicating whether the component can raise an event. (Inherited from Component.) |
![]() | CatalogLocation | Sets or gets the CatalogLocation for an instance of the DbCommandBuilder class. (Inherited from DbCommandBuilder.) |
![]() | CatalogSeparator | Sets or gets a string used as the catalog separator for an instance of the DbCommandBuilder class. (Inherited from DbCommandBuilder.) |
![]() | ConflictOption | Specifies which ConflictOption is to be used by the DbCommandBuilder. (Inherited from DbCommandBuilder.) |
![]() | Container | Gets the IContainer that contains the Component. (Inherited from Component.) |
![]() | DataAdapter |
Gets or sets a MySqlDataAdapter object for which SQL statements are automatically generated.
|
![]() | DesignMode | Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component.) |
![]() | Events | Gets the list of event handlers that are attached to this Component. (Inherited from Component.) |
![]() | QuotePrefix | Gets or sets the beginning character or characters to use when specifying database objects (for example, tables or columns) whose names contain characters such as spaces or reserved tokens. (Inherited from DbCommandBuilder.) |
![]() | QuoteSuffix | Gets or sets the ending character or characters to use when specifying database objects (for example, tables or columns) whose names contain characters such as spaces or reserved tokens. (Inherited from DbCommandBuilder.) |
![]() | SchemaSeparator | Gets or sets the character to be used for the separator between the schema identifier and any other identifiers. (Inherited from DbCommandBuilder.) |
![]() | SetAllValues | Specifies whether all column values in an update statement are included or only changed ones. (Inherited from DbCommandBuilder.) |
![]() | Site | (Inherited from Component.) |

Name | Description | |
---|---|---|
![]() | ApplyParameterInfo | (Overrides DbCommandBuilderApplyParameterInfo(DbParameter, DataRow, StatementType, Boolean).) |
![]() | CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.) |
![]() ![]() | DeriveParameters |
Retrieves parameter information from the stored procedure specified
in the MySqlCommand and populates the Parameters collection of the
specified MySqlCommand object.
This method is not currently supported since stored procedures are
not available in MySql.
|
![]() | Dispose | Releases all resources used by the Component. (Inherited from Component.) |
![]() | Dispose(Boolean) | Releases the unmanaged resources used by the DbCommandBuilder and optionally releases the managed resources. (Inherited from DbCommandBuilder.) |
![]() | Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | Finalize | Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.) |
![]() | GetDeleteCommand |
Gets the delete command.
|
![]() | GetDeleteCommand(Boolean) | Gets the automatically generated DbCommand object required to perform deletions at the data source, optionally using columns for parameter names. (Inherited from DbCommandBuilder.) |
![]() | GetHashCode | Serves as the default hash function. (Inherited from Object.) |
![]() | GetInsertCommand |
Gets the insert command.
|
![]() | GetInsertCommand(Boolean) | Gets the automatically generated DbCommand object required to perform insertions at the data source, optionally using columns for parameter names. (Inherited from DbCommandBuilder.) |
![]() | GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | GetParameterName(Int32) | (Overrides DbCommandBuilderGetParameterName(Int32).) |
![]() | GetParameterName(String) | (Overrides DbCommandBuilderGetParameterName(String).) |
![]() | GetParameterPlaceholder | (Overrides DbCommandBuilderGetParameterPlaceholder(Int32).) |
![]() | GetSchemaTable | (Overrides DbCommandBuilderGetSchemaTable(DbCommand).) |
![]() | GetService | (Inherited from Component.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetUpdateCommand |
Gets the update command.
|
![]() | GetUpdateCommand(Boolean) | Gets the automatically generated DbCommand object required to perform updates at the data source, optionally using columns for parameter names. (Inherited from DbCommandBuilder.) |
![]() | InitializeCommand | Resets the CommandTimeout, Transaction, CommandType, and UpdateRowSource properties on the DbCommand. (Inherited from DbCommandBuilder.) |
![]() | InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.) |
![]() | QuoteIdentifier | (Overrides DbCommandBuilderQuoteIdentifier(String).) |
![]() | RefreshSchema | Clears the commands associated with this DbCommandBuilder. (Inherited from DbCommandBuilder.) |
![]() | RowUpdatingHandler | Adds an event handler for the RowUpdating event. (Inherited from DbCommandBuilder.) |
![]() | SetRowUpdatingHandler | (Overrides DbCommandBuilderSetRowUpdatingHandler(DbDataAdapter).) |
![]() | ToString | Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.) |
![]() | UnquoteIdentifier | (Overrides DbCommandBuilderUnquoteIdentifier(String).) |

Name | Description | |
---|---|---|
![]() | Disposed | Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.) |

The MySqlDataAdapter does not automatically generate the SQL statements required to reconcile changes made to a DataSet with the associated instance of MySQL. However, you can create a MySqlCommandBuilder object to automatically generate SQL statements for single-table updates if you set the SelectCommand property of the MySqlDataAdapter. Then, any additional SQL statements that you do not set are generated by the MySqlCommandBuilder.
The MySqlCommandBuilder registers itself as a listener for RowUpdating events whenever you set the DataAdapter property. You can only associate one MySqlDataAdapter or MySqlCommandBuilder object with each other at one time.
To generate INSERT, UPDATE, or DELETE statements, the MySqlCommandBuilder uses the SelectCommand property to retrieve a required set of metadata automatically. If you change the SelectCommand after the metadata has is retrieved (for example, after the first update), you should call the [!:RefreshSchema] method to update the metadata.
The SelectCommand must also return at least one primary key or unique column. If none are present, an InvalidOperation exception is generated, and the commands are not generated.
The MySqlCommandBuilder also uses the Connection, CommandTimeout, and Transaction properties referenced by the SelectCommand. The user should call RefreshSchema if any of these properties are modified, or if the SelectCommand itself is replaced. Otherwise the InsertCommand, UpdateCommand, and DeleteCommand properties retain their previous values.
If you call Dispose, the MySqlCommandBuilder is disassociated from the MySqlDataAdapter, and the generated commands are no longer used.
![]() |
---|
Caution must be used when using MySqlCOmmandBuilder on MySql 4.0 systems. With MySql 4.0, database/schema information is not provided to the connector for a query. This means that a query that pulls columns from two identically named tables in two or more different databases will not cause an exception to be thrown but will not work correctly. Even more dangerous is the situation where your select statement references database X but is executed in database Y and both databases have tables with similar layouts. This situation can cause unwanted changes or deletes. This note does not apply to MySQL versions 4.1 and later. |

public static DataSet SelectRows(string myConnection, string mySelectQuery, string myTableName) { MySqlConnection myConn = new MySqlConnection(myConnection); MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(); myDataAdapter.SelectCommand = new MySqlCommand(mySelectQuery, myConn); MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter); myConn.Open(); DataSet ds = new DataSet(); myDataAdapter.Fill(ds, myTableName); //code to modify data in DataSet here //Without the MySqlCommandBuilder this line would fail myDataAdapter.Update(ds, myTableName); myConn.Close(); return ds; }
Public Shared Function SelectRows(myConnection As String, mySelectQuery As String, myTableName As String) As DataSet Dim myConn As New MySqlConnection(myConnection) Dim myDataAdapter As New MySqlDataAdapter() myDataAdapter.SelectCommand = New MySqlCommand(mySelectQuery, myConn) Dim cb As SqlCommandBuilder = New MySqlCommandBuilder(myDataAdapter) myConn.Open() Dim ds As DataSet = New DataSet myDataAdapter.Fill(ds, myTableName) ' Code to modify data in DataSet here ' Without the MySqlCommandBuilder this line would fail. myDataAdapter.Update(ds, myTableName) myConn.Close() End Function 'SelectRows
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.
