ASP.NET provides a rich set of controls that are well-integrated with the data access interface provided by ADO.NET. This section provides information on how you can use ASP.NET server controls to bind to the results of SQL queries and XML data files.
In particular, this document steps through code examples that use the ASP.NET templated controls <asp:Repeater
>, <asp:DataList
>, and <asp:DataGrid
> controls to display the results of database queries fetched into an instance of the DataReader class.
These samples demonstrate how you can use the simple power of the ASP.NET databinding model, to dynamically generate the column values within each row of a DataReader into the corresponding items of said controls.
Note that for all the samples, we are using a DataReader to bind directly to the controls. DataReaders retrieve a read-only, forward-only stream of data from a database, and are appropriate when the need is to simply "read" the results after executing a query to the data source. Any of these samples, though, could be re-written to use a DataSet as well.
The material covered in this section assumes some familiarity with database fundamentals and the Structured Query Language ( SQL ). And if you haven’t done so, I suggest you start with the ADO.NET Primer.
Now let’s take a closer look at how all these are done.