To see how to interact with a database, you'll begin by creating a web application that can be used to display information about the NorthWind database (that comes with SQLExpress and SQL Server).
Start by creating a new web site called WebNorthWind.
You'll be working with the Customers table in the NorthWind database, so rename your .aspx file from default.aspx to Customers.aspx.
Remember to change the class name in the code file and in the page directive.
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.
SqlDataSource control onto the form (see Figure 9-1). You can drag and drop this control either into Design view or into Source view. Switch to Design view, and click on the smart tag to open its menu. Clicking on Configure Data Source... opens the Configure Data Source Wizard. Your first option is to choose an existing connection or to press the button to create a new connection.
Figure 9-1. SqlDataSource control on form
If you do not see the
SqlDataSource control, choose View → Non Visual Controls.
Click on New Connection. When you create a new connection, you'll be asked to fill in the Server name. Decide if you want to use a trusted connection (Windows Authentication) or use a specific ...