Asp. NET:ADO.NET's DataAdapter Object _ self-study Process
Source: Internet
Author: User
The DataAdapter object can hide and connection the details of communication with the Command object, create and initialize the DataTable by DataAdapter Object, and combine the DataSet object to store the data table copy in memory. Implementing offline database operations, in fact, in 8.1.2, we have demonstrated how to use the DataAdapter object for database connections when we introduce the DataSet data model. The DataAdapter object allows data from the DataSet object to be saved to the data source, or read from the data source, and can also be added, deleted, updated, and so on by the underlying data storage body.
The DataAdapter object contains four different operation commands, as follows:
(1), SelectCommand: Used or to go to the record in the data source;
(2), InsertCommand: Used to insert a new record into the data source;
(3), UpdateCommand: Used to update the data in the data source;
(4), DeleteCommand: Used to delete the record in the source of the number of dramas.
Depending on the database being used, DataAdapter also has two different objects: OleDbDataReader and SqlDataReader objects, which are used to access databases and SQL Server databases that support ADO Managed provider, respectively.
When you use the OleDbDataReader object, use the method:
[Visual Basic Language]
Public Function Selectoledbsrvrows (DataSet as DataSet, connection as String, query as String) as DataSet
Dim Conn as New OleDbConnection (connection)
Dim Adapter as New OleDbDataAdapter ()
Adapter. SelectCommand = new OleDbCommand (query, conn)
Adapter. Fill (DataSet)
return dataset
End Function
[C # Language]
Public DataSet Selectoledbsrvrows (DataSet dataset,string connection,string query)
{
OleDbConnection conn = new OleDbConnection (connection);
OleDbDataAdapter adapter = new OleDbDataAdapter ();
Adapter. SelectCommand = new OleDbCommand (query, conn);
Adapter. Fill (DataSet);
return dataset;
}
When you use the Sqldatareaderd object, you use the following method:
[Visual Basic Language]
Public Function Selectsqlsrvrows (DataSet as DataSet, connection as String, query as String) as DataSet
Dim Conn as New SqlConnection (connection)
Dim Adapter as New SqlDataAdapter ()
Adapter. SelectCommand = new SqlCommand (query, conn)
Adapter. Fill (DataSet)
return dataset
End Function
[C # Language]
Public DataSet Selectsqlsrvrows (DataSet dataset,string connection,string query)
{
SqlConnection conn = new SqlConnection (connection);
SqlDataAdapter adapter = new SqlDataAdapter ();
Adapter. SelectCommand = new SqlCommand (query, conn);
Adapter. Fill (DataSet);
return dataset;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service