OleDbCommandBuilder Class
Assembly: System.Data (in system.data.dll)
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 is retrieved, such as 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 one or more 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 creates an OleDbCommandBuilder.
Public Shared Function UpdateRows(connectionString As String, _ queryString As String, tableName As String) As DataSet Dim dataSet As DataSet = New DataSet Using connection As New OleDbConnection(connectionString) Dim adapter As New OleDbDataAdapter() adapter.SelectCommand = New OleDbCommand(queryString, connection) Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(adapter) connection.Open() adapter.Fill(dataSet, tableName) ' Code to modify data in DataSet here ' Without the OleDbCommandBuilder this line would fail. adapter.Update(dataSet, tableName) End Using Return dataSet End Function
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DbCommandBuilder
System.Data.OleDb.OleDbCommandBuilder
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
OleDbCommandBuilder MembersSystem.Data.OleDb Namespace