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

Get Sams Teach Yourself ADO.NET in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.