O'Reilly logo

Sams Teach Yourself ADO.NET in 24 Hours by Paul Bertucci, Jason Lefebvre

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Binding DataReader Results to a Web Control

The most common use for the DataReader is to bind it to Web controls, much in the same way as you'd bind a DataSet. Other than the fact that you've eliminated overhead by not creating a DataSet, binding to a DataReader is almost exactly the same as binding to a DataSet. The code in Listing 8.4 demonstrates how to bind the DataReader. When run, this Web form will appear identical to the one in Figure 8.1. Notice that in line 22, the DataReader object is passed directly to the DataSource of the DataGrid Web control.

Listing 8.4. Data Binding the DataReader Object to a Web Control
 <% @Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <HTML> <HEAD> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required