| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
OleDbCommandBuilder ClassProvides a means to automatically generate single-table commands used to reconcile changes made to a DataSet with the associated database.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Visibility | Name | Value Type | Accessibility |
|---|---|---|---|
| public | DataAdapter | OleDbDataAdapter | [ Get , Set ] |
| Visibility | Name | Parameters | Return Type |
|---|---|---|---|
| protected | ApplyParameterInfo | ( DbParameter parameter , DataRow datarow , StatementType statementType , Boolean whereClause ) | Void |
| public static | DeriveParameters | ( OleDbCommand command ) | Void |
| public | GetDeleteCommand | ( ) | OleDbCommand |
| public | GetDeleteCommand | ( Boolean useColumnsForParameterNames ) | OleDbCommand |
| public | GetInsertCommand | ( Boolean useColumnsForParameterNames ) | OleDbCommand |
| public | GetInsertCommand | ( ) | OleDbCommand |
| protected | GetParameterName | ( String parameterName ) | String |
| protected | GetParameterName | ( Int32 parameterOrdinal ) | String |
| protected | GetParameterPlaceholder | ( Int32 parameterOrdinal ) | String |
| public | GetUpdateCommand | ( ) | OleDbCommand |
| public | GetUpdateCommand | ( Boolean useColumnsForParameterNames ) | OleDbCommand |
| public | QuoteIdentifier | ( String unquotedIdentifier , OleDbConnection connection ) | String |
| public | QuoteIdentifier | ( String unquotedIdentifier ) | String |
| protected | SetRowUpdatingHandler | ( DbDataAdapter adapter ) | Void |
| public | UnquoteIdentifier | ( String quotedIdentifier , OleDbConnection connection ) | String |
| public | UnquoteIdentifier | ( String quotedIdentifier ) | String |
The OleDbDataAdapter does not automatically generate the SQL statements required to reconcile changes made to a DataSet with the associated data source. However, you can create an OleDbCommandBuilder object to automatically generate SQL statements for single-table updates if you set the SelectCommand property of the OleDbDataAdapter. Then, any additional SQL statements that you do not set are generated by the OleDbCommandBuilder.
The OleDbCommandBuilder registers itself as a listener for RowUpdating events whenever you set the DataAdapter property. You can only associate one OleDbDataAdapter or OleDbCommandBuilder object with each other at one time.
To generate INSERT, UPDATE, or DELETE statements, the OleDbCommandBuilder 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 OleDbCommandBuilder 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 OleDbCommandBuilder is disassociated from the OleDbDataAdapter, and the generated commands are no longer used.
The following example uses the OleDbCommand, along OleDbDataAdapter and OleDbConnection, to select rows from a data source. The example is passed an initialized DataSet, a connection string, a query string that is an SQL SELECT statement, and a string that is the name of the data source table. The example then initializes an OleDbCommandBuilder.
public DataSet SelectOleDbSrvRows ( DataSet myDataSet, string myConn,
string query, string myTableName ) {
OleDbConnection myConn = new OleDbConnection ( myConn );
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter ( );
myDataAdapter.SelectCommand = new OleDbCommand ( query, myConn );
OleDbCommandBuilder custCB = new OleDbCommandBuilder ( myDataAdapter );
myConn.Open ( );
DataSet custDS = new DataSet ( );
myDataAdapter.Fill ( custDS, "Customers" );
// ... code to modify data in dataset here ...
// Without the OleDbCommandBuilder this line would fail
myDataAdapter.Update ( custDS, "Customers" );
myConn.Close ( );
return custDS;
}
| ||
| C# | VB | |
Check out related books at Amazon
© 2000-2008 Rey Nuñez All rights reserved.
If you have any question, comment or suggestion
about this site, please send us a note
You can help support aspxtreme