asp.net.ph

Skip Navigation LinksHome > Data Access in Web Forms > Displaying Information From a Database

Displaying Information From a Database


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>, <asp:DataGrid> and <asp:GridView> controls — to display the results of database queries fetched into an instance of the DataReader class.

The following 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.

While the samples use the methods described in Calling Data Functions in Code Behind to connect and bind to a DataSource, comparative samples using data source controls will be shown as we walk through each sample later.

Binding a DataReader to a Repeater
RunSample | View Source
Binding a DataReader to a DataList
RunSample | View Source
Binding a DataReader to a DataGrid
RunSample | View Source
Binding a DataReader to a GridView
RunSample | View Source

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 the 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.

Next Section

Displaying Data in a Repeater Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note