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

DataReader Versus DataAdapter

In Hour 6, you saw how to use the Command object in conjunction with the DataAdapter object to retrieve records from the database and place them into a DataSet. The DataSet was then bound to a Web control such as the DataGrid and displayed in a Web form. The code in Listing 8.1 is a review of the ADO.NET code required to perform these tasks.

Listing 8.1. Retrieving Records with the DataAdapter
 <script language="VB" runat="server" > Sub Page_Load(Source as Object, E as EventArgs) Dim conn as New SqlConnection("Initial " + _ Catalog=Northwind;Server=(local);UID=sa;PWD=;") Dim cmd as New SqlCommand("SELECT * FROM Employees", conn) Dim adapt as New SqlDataAdapter(cmd) Dim dsEmployees as New DataSet() conn.Open() adapt.Fill(dsEmployees, ...

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