Published in .NET By pushkar
Data Reader OR Data Adapter???????
The OleDbDataReader (and SQLDataReader) runs a query and provides once-only access to the results. The DataReader is appropriate for once-off recovery and display of data.
The OleDbDataAdapter (and SqlDataAdapter) runs a query and stores the results in a DataTable.
This is used when the results need to be counted, paged, sorted and so on.
A DataSet contains one or more DataTables
A DataTable stores data in a database-type row-and column format. It is an in-memory object which stores the information in rows and columns. The DataTable uses the DataAdapter’s ‘fill’ method to run the query and retrieve the data (and the field name and data type). The DataTable is a copy in memory to the data in the database and it does not remain connected to the database whilst it is scrolled or paged or sorted.
A DataRelation defines a logical relationship between two DataTables
A DataView provides a sorted or filtered view of the contents of a DataTable
The objects used to make connections, provide a connection string, open a connection and so on are contained in the Namespaces “System.Data” and “System.Data.OleDb” or (for SQL Server) “System.Data.SqlClient”
Most of the rest of the example code (and the DataGrid) is the same. These are the differences:-
Dim dap As OleDbDataAdapter
Dim dst As DataSet
The dataset is defined and then filled. This is the datasource for the Grid, which is then bound.
dst = New DataSet()
dap.Fill(dst,”text”)
grid.DataSource = dst.Tables(”text”)
grid.DataBind
Use DataReader when you need just to display the data in one go - which is not all that common.