ASP. NET: DataAdapter object of ADO. NET

Source: Internet
Author: User

The DataAdapter object can hide the details of communication with the Connection and Command objects. It creates and initializes a DataTable through the DataAdapter object, so that it can be combined with the DataSet object to store data table copies in the memory to implement offline database operations, in fact, in Section 8.1.2, we demonstrated how to use the DataAdapter object for database connection when introducing the DataSet data model. The DataAdapter object allows you to save data from a DataSet object to a data source, read data from the data source, and add, delete, and update data using the underlying data storage body.

The DataAdapter object contains four different operation commands:

(1) SelectCommand: Used to or remove records from the data source;

(2) InsertCommand: used to insert a new record into the data source;

(3) UpdateCommand: Used to update data in the data source;

(4) DeleteCommand: Used to delete records from several drama sources.

DataAdapter has two different objects: OleDbDataReader and SqlDataReader, which are used to access databases that support ADO Managed providers and SQL Server databases.

How to Use OleDbDataReader:

[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 using the SqlDataReaderd object, 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;
}

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.