asp.net.ph

OleDbDataAdapter Class

System.Data.OleDb Namespace


Represents a set of data commands and a database connection which are used to fill the DataSet and update the data source.

OleDbDataAdapter Class Members

Collapse   Constructors

Visibility Constructor Parameters
public OleDbDataAdapter ( )
public OleDbDataAdapter ( OleDbCommand selectCommand )
public OleDbDataAdapter ( String selectCommandText , String selectConnectionString )
public OleDbDataAdapter ( String selectCommandText , OleDbConnection selectConnection )

Collapse   Properties

Visibility Name Value Type Accessibility
public DeleteCommand OleDbCommand [ Get , Set ]
public InsertCommand OleDbCommand [ Get , Set ]
public SelectCommand OleDbCommand [ Get , Set ]
public UpdateCommand OleDbCommand [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
protected CreateRowUpdatedEvent ( DataRow dataRow , IDbCommand command , StatementType statementType , DataTableMapping tableMapping ) RowUpdatedEventArgs
protected CreateRowUpdatingEvent ( DataRow dataRow , IDbCommand command , StatementType statementType , DataTableMapping tableMapping ) RowUpdatingEventArgs
public Fill ( DataSet dataSet , Object ADODBRecordSet , String srcTable ) Int32
public Fill ( DataTable dataTable , Object ADODBRecordSet ) Int32
protected OnRowUpdated ( RowUpdatedEventArgs value ) Void
protected OnRowUpdating ( RowUpdatingEventArgs value ) Void

Collapse   Events

Remarks

The OleDbDataAdapter serves as a bridge between an OLEDB data source and a DataSet for retrieving and saving data. The OleDbDataAdapter provides this bridge by using:

  • Fill to load data from the data source into the DataSet, and
  • Update to send changes made in the DataSet back to the data source.

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

Note that some OLE DB providers, including the MSDataShape provider, do not return base table or primary key information. As a result, the OleDbDataAdapter cannot properly set the PrimaryKey property on any created DataTable. In such cases you should explicitly specify primary keys for tables in the DataSet.

The OleDbDataAdapter also includes the SelectCommand, InsertCommand, DeleteCommand, UpdateCommand, and TableMappings properties for facilitating the loading and updating of data.

A new instance of OleDbDataAdapter can be constructed in four ways. For a list of the different versions and the parameters that can be used with each, see the OleDbDataAdapter constructor.

Example

The following example shows using an OleDbDataAdapter to fill a DataSet with records retrieved from a data source. Here, the entire logic is encapsulated within a Page_Load event handler that essentially:

  1. establishes a connection to the database,
  2. initializes an instance of a DataSet to contain the database information,
  3. and then enumerates the contents of the DataSet into an html table.

string html;

protected void Page_Load ( Object Src, EventArgs e ) {
   // set up the connection
   OleDbConnection myConn = new OleDbConnection (
      ( "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + 
      Server.MapPath ( "~/app_data/dbtutor.mdb" ) );
   // set up the query
   OleDbDataAdapter myAdapter = new OleDbDataAdapter (
      "SELECT * FROM Products", myConn );

   // instantiate dataset object
   DataSet myData = new DataSet ( );
   // fill with query results
   myAdapter.Fill ( myData, "Customers" );

   // display dataset contents into html table
   // first open the table and set up the table headers
   html += "<table cellspacing=1 class='data' width=80%>";
   html += "<tr>";
   html += "<th>Customer ID</th>";
   html += "<th>Company Name</th>";
   html += "</tr>";

   // loop thru the dataset
   foreach ( DataRow Customer in myData.Tables [ "Customers" ].Rows ) {   
      html += "<tr>";
      html += "<td>" + Customer [ "CustomerID" ].ToString ( ) + "</td>";
      html += "<td>" + Customer [ "CompanyName" ].ToString ( ) + "</td>";
      html += "</tr>";
   }

   // close the table
   html += "</table>";
}
  C# VB

 Show me 

See Also

OleDbConnection   OleDbCommand   DataSet   DataTable Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 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 asp.net.ph