Chapter 5. Data

One of the stated goals of .NET 2.0 is to push more of the plumbing into the .NET Framework and to provide controls for Windows and web developers that reduce the amount of code they will write. Nowhere is this seen more profoundly than when writing code for interacting with databases.

Bind to Data Without Writing Code

In .NET 2.0 you write far less code to set up database interactions, but you do not sacrifice control when creating, displaying, updating, or deleting data. In fact, you can create a very powerful sorted, paged grid of data from your database with virtually no code at all.

How do I do that?

Tip

You will need to have Northwind installed on your database to do the labs in this chapter. If you have installed SQL Server (Developer or Production version) or Access, you already have Northwind. If you have SQL Server Express, download the appropriate setup files from the Microsoft web site (http://www.microsoft.com).

First, create a new web application and name it DataBindingNoCode. Click the Data tab of the Toolbox and drag a GridView control onto the default web form, Default.aspx.

Your first job is to set up the database connection. You can do this in a number of ways, but it’s easiest to click the smart tag and drop down the Choose Data Source list. Click <New data source...>, as shown in Figure 5-1.

Creating a new data source
Figure 5-1. Creating a new data source

Note

With .NET 2.0 you ...

Get Visual C# 2005: A Developer's Notebook 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.