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;
}