Chapter 11. Web Data Access
In the previous chapter, you created forms, but they did not interact with real data. In this chapter, you'll begin to extract data from the database and fill in your forms. You'll do this incrementally, adding complexity as you go. You'll put a premium on using data controls and letting the controls manage the "plumbing" of database interaction.
Getting Data from a Database
To see how to interact with a database, begin by creating a new web application that can be used to display information about the Northwind database. Call it WebNorthWind
, as shown in Figure 11-1.
Figure 11-1. Creating the WebNorthWind web site
You'll be working with the Customers table in the Northwind database, so rename your .aspx file from Default.aspx to Customers.aspx (don't forget to change the class name both in the code file and in the page directive!).
Create a Data Connection
You need a connection to the database. You can explicitly create one, or you can use a control that depends on having a connection and one will be created for you. Let's start by explicitly creating one.
Drag a SqlDataSource
control onto the form, as shown in Figure 11-2.
Figure 11-2. Data source control
The SqlDataSource
control will appear on your form, as shown in Figure 11-3.
Figure 11-3. SqlDataSource ...
Get Programming Visual Basic 2005 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.