Data adapters act as a bridge between data source and in-memory data objects such as the DataSet.
To access the data source adapters uses the command objects.
The SqlDataAdapter class's SelectCommand property is used to hold an SqlCommand that retrieves data from the data source.
After retrieving the data, adapter will place the result of the query into a DataSet or DataTable. The SqlDataAdapter also has UpdateCommand,DeleteCommand, and InsertCommand properties.
These are also SqlCommand objects, used to write changes made to a DataSet or DataTable back to the data source.
The SqlDataAdapter class's SelectCommand property is used to fill a DataSet with data from an SQL Server database.
This property is an SqlCommand Object and is used to specify what data to select and how to select the data
Like SqlCommand, SelectCommand also have three properties like:-
Dim x As SqlConnection=New SqlConnection("Data Source=PC\SQLEXPRESS; Initial Catalog=college;User ID=sa;Password=123") Dim y As New SqlDataAdapter() y.SelectCommand = New SqlCommand() y.SelectCommand.Connection = x y.SelectCommand.CommandText = "Select * from books" y.SelectCommand.CommandType = CommandType.Text Dim z As DataSet = New DataSet() x.Open() y.Fill(z, "b") X.Close()
We can use the Fill method to populate a Dataset object with the data that the SqlDataAdapter retrieves from the data store using its SelectCommand.
Dim z As DataSet = New DataSet() y.Fill(z,"books")