Dataadapters object can be hidden and the details of the Connection, Command objects communication, through setting up, initialize the DataTable dataadapters object, and combined with the DataSet object is stored in the memory copy of the data table, an off-line database operations, in fact in 8.1.2 section, we introduce the DataSet data model was demonstrated how to use dataadapters object for the database Connection. Dataadapters object allows to save data in a DataSet object to a data source, and can be read from the data source data, and also can be the underlying data save data to add, delete, update, etc.

        Dataadapters object contains four different commands, respectively, as follows:

        (1), SelectCommand: used to or to the records in the data source;

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

        (3) and UpdateCommand: used to update the data in the data source.

        (4) and DeleteCommand: used to delete records in the source number play.

        According to the use of different database, dataadapters also has two different objects: OleDbDataReader and SqlDataReader object, used to access support ADO  respectively; Managed  The Provider of database and SQL  Server database.

        When use OleDbDataReader object, method of use:

  ] [Visual  the Basic language  

public  Function  SelectOleDbSrvRows (dataSet  As  the DataSet,   connection  As  String,   query  As  String)   As  The DataSet
        Dim  Conn  As  New  OleDbConnection (connection)
        Dim  Adapter  As  New  OleDbDataAdapter ()
        Adapter. SelectCommand =  New  OleDbCommand (query,   conn)
        Adapter. The Fill (dataset)
        Return  The dataset
End  The Function

[c #language]

public  DataSet  SelectOleDbSrvRows (DataSet  the dataset, string  connection, string  query)  
{
        OleDbConnection  Conn =  New  OleDbConnection (connection);
        OleDbDataAdapter  Adapter =  New  OleDbDataAdapter ();
        Adapter. SelectCommand =  New  OleDbCommand (query,   conn);
        Adapter. The Fill (dataset);
        Return  The dataset.
}

        When using SqlDataReaderd object, using the method is:

] [Visual  the Basic language  

public  Function  SelectSqlSrvRows (dataSet  As  the DataSet,   connection  As  String,   query  As  String)   As  The DataSet
        Dim  Conn  As  New  SqlConnection (connection)
        Dim  Adapter  As  New  SqlDataAdapter ()
        Adapter. SelectCommand =  New  SqlCommand (query,   conn)
        Adapter. The Fill (dataset)
        Return  The dataset
End  The Function

[c #language]

public  DataSet  SelectSqlSrvRows (DataSet  the dataset, string  connection, string  query)  
{
        SqlConnection  Conn =  New  SqlConnection (connection);
        SqlDataAdapter  Adapter =  New  SqlDataAdapter ();
        Adapter. SelectCommand =  New  SqlCommand (query,   conn);
        Adapter. The Fill (dataset);
        Return  The dataset.

}


This concludes the body part