asp.net.ph

IDataAdapter Interface

System.Data Namespace


Represents the base set of properties and methods used to retrieve records from a data source into a DataSet, and to reconcile the changes back into the data source.

IDataAdapter Interface Members

Collapse   Properties

Visibility Name Value Type Accessibility
public MissingMappingAction MissingMappingAction [ Get , Set ]
public MissingSchemaAction MissingSchemaAction [ Get , Set ]
public TableMappings ITableMappingCollection [ Get ]

Collapse   Methods

Visibility Name Parameters Return Type
public Fill ( DataSet dataSet ) Int32
public FillSchema ( DataSet dataSet , SchemaType schemaType ) DataTable
public GetFillParameters ( ) IDataParameter
public Update ( DataSet dataSet ) Int32

Classes that Implement IDataAdapter


Class Description
DataAdapter Represents a set of data commands and a database connection that are used to fill the DataSet and update the data source.

Remarks

The IDataAdapter interface allows an inheriting class to implement a DataAdapter class, which represents the bridge between a data source and a DataSet.

An application does not create an instance of the IDataAdapter interface directly, but implements an instance of a class that inherits IDbDataAdapter.

Classes that inherit IDataAdapter must implement the inherited members, and typically define additional members to add provider-specific functionality. For example, the IDataAdapter interface defines a Fill method that takes a DataSet as a parameter. In turn, the OleDbDataAdapter class inherits the Fill method, and also defines two additional overloads of the Fill method that take an ADO Recordset object as a parameter.

Notes to Implementers: To promote consistency among .NET data providers, name the inheriting class in the form Prv DataAdapter where Prv is the uniform prefix given to all classes in a specific .NET data provider namespace. For example, Sql is the prefix of the SqlDataAdapter class in the System.Data.SqlClient namespace.

When you inherit from the IDataAdapter interface, you should implement the following constructors:

Item Description
PrvDataAdapter ( ) Initializes a new instance of the PrvDataAdapter class.
PrvDataAdapter ( PrvCommand selectCommand ) Initializes a new instance of the PrvDataAdapter class with the specified SQL SELECT statement.
PrvDataAdapter ( string selectCommandText, string selectConnectionString ) Initializes a new instance of the PrvDataAdapter class with an SQL SELECT statement and a connection string.
PrvDataAdapter ( string selectCommandText, PrvConnection selectConnection ) Initializes a new instance of the PrvDataAdapter class with an SQL SELECT statement and a PrvConnection object.

For more information about implementing .NET data providers, see Implementing a .NET Data Provider. For more information about using the DataAdapter class, see Populating a DataSet from a DataAdapter.

Example

The following example shows a generic method that is used extensively in the demos of this workshop. Essentially, the method selects records from a given data source and returns a filled DataSet.

For re-usability, the method takes as parameters the statement to use in the query and the database from which to retrieve the result set. The database is passed to the connection string, while the query is passed to the IDataAdapter.

This example implements an SqlDataAdapter, but can be adapted to use an OleDbDataAdapter as well, both of which derive from IDataAdapter.

DataSet fetchData ( string query, string db ) {
   // connect to data source
   SqlConnection myConn = new SqlConnection (
      "server=( local )\\NetSDK; trusted_connection=yes; database=" + db );

   // initialize dataadapter
   SqlDataAdapter myAdapter = new SqlDataAdapter ( query, myConn );

   // initialize and fill DataSet
   DataSet myDataSet = new DataSet ( );
   myAdapter.Fill ( myDataSet );

   // return dataset
   return myDataSet;
}
  C# VB

The below examples illustrate using the method above, passing different parameters to query different data sources and return varying result sets.

Dynamically Retrieving Data From Any SQL Server Source
Run Sample | View Source
DataView Count Property Example
Run Sample | View Source
DataRowView CreateChildView Method
Run Sample | View Source

See Also

DataSet   SqlDataAdapter   OleDbDataAdapter 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