Sideway
output.to from Sideway
Draft for Information Only

Content

System.Data.OleDB
OleDbCommandBuilder Class
 Definition
  In this article
 Examples
 Remarks
 Constructors
 Properties
 Methods
 Events
 Applies to
   .NET Core
   .NET Framework
   .NET Platform Extensions
   Xamarin.Mac
 See also
 Examples
 Source/Reference

System.Data.OleDB

The System.Data.OleDb namespace is the.NET Framework Data Provider for OLE DB.

OleDbCommandBuilder Class

Definition

Namespace:
System.Data.OleDb
Assemblies:
System.Data.dll, System.Data.OleDb.dll

Automatically generates single-table commands that are used to reconcile changes made to a DataSet with the associated database. This class cannot be inherited.

In this article

  1. Definition
  2. Examples
  3. Remarks
  4. Constructors
  5. Properties
  6. Methods
  7. Events
  8. Applies to
  9. See also
C#
public sealed class OleDbCommandBuilder : System.Data.Common.DbCommandBuilder
Inheritance
Object MarshalByRefObject Component OleDbCommandBuilder

Examples

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.

C#
public static DataSet UpdateRows(string connectionString,
    string queryString, string tableName)
{
    DataSet dataSet = new DataSet();
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        OleDbDataAdapter adapter = new OleDbDataAdapter();
        adapter.SelectCommand = new OleDbCommand(queryString, connection);
        OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter);

        connection.Open();

        adapter.Fill(dataSet, tableName);

        //code to modify data in DataSet here

        cb.GetDeleteCommand();
        //Without the OleDbCommandBuilder this line would fail
        adapter.Update(dataSet, tableName);

        connection.Close();
    }
    return dataSet;
}

Remarks

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.

Constructors

OleDbCommandBuilder()

Initializes a new instance of the OleDbCommandBuilder class.

OleDbCommandBuilder(OleDbDataAdapter)

Initializes a new instance of the OleDbCommandBuilder class with the associated OleDbDataAdapter object.

Properties

CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container

Gets the IContainer that contains the Component.

(Inherited from Component)
DataAdapter

Gets or sets an OleDbDataAdapter 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)
Site

Gets or sets the ISite of the Component.

(Inherited from Component)

Methods

CreateObjRef(Type)

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(OleDbCommand)

Retrieves parameter information from the stored procedure specified in the OleDbCommand and populates the Parameters collection of the specified OleDbCommand object.

Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean)

Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetDeleteCommand()

Gets the automatically generated OleDbCommand object required to perform deletions at the data source.

GetDeleteCommand(Boolean)

Gets the automatically generated OleDbCommand object required to perform deletions at the data source.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetInsertCommand()

Gets the automatically generated OleDbCommand object required to perform insertions at the data source.

GetInsertCommand(Boolean)

Gets the automatically generated OleDbCommand object required to perform insertions at the data source.

GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetUpdateCommand()

Gets the automatically generated OleDbCommand object required to perform updates at the data source.

GetUpdateCommand(Boolean)

Gets the automatically generated OleDbCommand object required to perform updates at the data source, optionally using columns for parameter names.

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(String)

Given an unquoted identifier in the correct catalog case, returns the correct quoted form of that identifier. This includes correctly escaping any embedded quotes in the identifier.

QuoteIdentifier(String, OleDbConnection)

Given an unquoted identifier in the correct catalog case, returns the correct quoted form of that identifier. This includes correctly escaping any embedded quotes in the identifier.

ToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.

(Inherited from Component)
UnquoteIdentifier(String)

Given a quoted identifier, returns the correct unquoted form of that identifier. This includes correctly un-escaping any embedded quotes in the identifier.

UnquoteIdentifier(String, OleDbConnection)

Given a quoted identifier, returns the correct unquoted form of that identifier. This includes correctly un-escaping any embedded quotes in the identifier.

Events

Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

Applies to

.NET Core

3.0 Preview 8

.NET Framework

4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5 4.0 3.5 3.0 2.0 1.1

.NET Platform Extensions

3.0 Preview 8

Xamarin.Mac

3.0

See also

 

Examples

Examples of OleDbCommandBuilder Class
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
       <title>Sample Page</title>
       <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
       <script runat="server" >
           Sub Page_Load()
               Dim xstr As String
               Dim xconn As New System.Data.OleDb.OleDbConnection
               xconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=T:\test.mdb;User Id=admin;Password=;"
               xconn.Open()
               xstr = xstr + "Connection xconn to database test.mdb  is opened successfully.<br />"
               Dim xadapt As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter()
               Dim xcomm As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand()
               xcomm.Connection = xconn
               xcomm.CommandText = "Select * from T1"
               xadapt.SelectCommand = xcomm
               xstr = xstr + "Dataadapter xadapt.SelectCommand is assigned to SELECT * FROM T1 through xconn successfully.<br />"
               Dim xdata As New System.Data.DataSet
               xadapt.Fill(xdata,"T1")
               xstr = xstr + "Dataset xdata is filled with dataadapter xadapt.fill successfully.<br />"
               xstr = xstr + "Dataset xdata.tables(T1).rows(0).item(1):" + xdata.Tables("T1").Rows(0).Item("f1") + "<br />"
               
               
               Dim xcommb As System.Data.OleDb.OleDbCommandBuilder = new System.Data.OleDb.OleDbCommandBuilder
               xcommb.DataAdapter = xadapt
               xstr = xstr + "OleDbCommandBuilder xcommb is assigned to xadapter successfully.<br />"
               xcommb.GetInsertCommand()
               xstr = xstr + "xcommb.GetInsertCommand(): " + xcommb.GetInsertCommand.CommandText + "<br />"
               xcommb.GetUpdateCommand()
               xstr = xstr + "xcommb.GetUpdateCommand(): " + xcommb.GetUpdateCommand.CommandText + "<br />"
               xcommb.GetDeleteCommand()
               xstr = xstr + "xcommb.GetDeleteCommand(): " + xcommb.GetDeleteCommand.CommandText + "<br />"
               
               
               Dim x1 As String ="5"
               Dim x2 As String ="6"
               Dim row As System.Data.DataRow = xdata.Tables(0).NewRow()
               row("f1") = x1
               row("f2") = x2
               xdata.Tables(0).Rows.Add(row)
               xstr = xstr + "One row is inserted to Dataset xdata successfully.<br />"
               
               
               x1 ="1"
               x2 ="7"
               row = xdata.Tables(0).Rows(0)
               row("f2") = x2
               xstr = xstr + "One row of Dataset xdata is updated successfully.<br />"
               
               
               x1 ="5"
               row = xdata.Tables(0).Rows(2)
               row.Delete()
               xstr = xstr + "One row is deleted from Dataset xdata successfully.<br />"
               
               
               xadapt.Update(xdata,"T1")
               xstr = xstr + "Database T1 is updated from Dataset xdata successfully.<br />"
               xadapt.Dispose()
               xdata.Dispose()
               xconn.Close()
               xstr = xstr + "Connection xconn is closed successfully.<br />"
               lbl01.Text = xstr
           End Sub
       </script>
    </head>
    <body>
<%Response.Write("<p>Results on "& Request.ServerVariables("SERVER_SOFTWARE") & " .net: " & System.Environment.Version.ToString & " " & ScriptEngine & " Version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "</p>")%>
       <% Response.Write ("<h1>This is a Sample Page of OleDbCommandBuilder Class</h1>") %>
       <p>
           <%-- Set on Page_Load --%>
           <asp:Label id="lbl01" runat="server" />
       </p>
    </body>
</html>
HTML Web Page Embedded Output:

Source/Reference


©sideway

ID: 201100005 Last Updated: 11/5/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019