Return to the "ASP.net 2.0 Data Tutorial directory"
Introduction
As Web developers, our lives revolve around data manipulation. We build databases to store data, write code to access and modify data, and design Web pages to collect and summarize data. This article is the first of a lengthy series of tutorials that explore the techniques for implementing these common data access patterns in asp.net 2.0. We'll start with creating a software framework that includes a data access layer (DAL) that uses a strongly typed DataSet, a business logic layer that enforces user-defined business rules (BLL), and a presentation layer composed of asp.net pages that share page layouts. After laying the groundwork for this backend, we will begin to turn to the report, demonstrating how to display, summarize, collect, and validate data for Web applications. These tutorials are designed to be concise, use a lot of screenshots, and provide step-by-step-by-step instructions to take you through the development process. Each tutorial has a C # version and a VB version, and is accompanied by a complete coded download. (This first tutorial is long, but other tutorials will be available in a more digestible space later.) )
In these tutorials, we will use the Microsoft SQL Server Express version of the Northwind database, which is placed in the App_Data directory. In addition to the database files, the App_Data directory has SQL scripts for creating the database, in case you want to use a different database version. You can also download these scripts directly from Microsoft, if you like. If you use a different SQL Server version of the Northwind database, you need to update the northwndconnectionstring settings in the Web.config file. The Web application in this tutorial is a file-based Web site project built with the visual Studio 2005 Professional Edition. However, all tutorials can be run in the free version of Visual Studio 2005, the Visual Web developer.
In this tutorial, we'll start from scratch, create a data access layer (DAL), then create a business Logic layer (BLL) in the second tutorial, and design the page layout and navigation in the third tutorial. Future tutorials will be based on these three tutorials. In the first tutorial, we have a lot to discuss, so please open visual Studio and let's get our hands on it!
First step: Create a Web project, configure the database connection
Before we start creating the data Access Layer (DAL), we first need to create a Web site and build a database. We started by creating a asp.net Web site based on the file system. Order below, open the File menu, select a new Web site, the system will display a new Web Site dialog box, select the ASP.net site template (Web site template), set the positioning (Location) List of options for the file system ( File System), then select the folder where this site is placed, and then choose the programming language for C #.
Figure 1: Creating a File system based Web site
Visual Studio generates a new Web site for you, along with a Web page called Default.aspx, and a App_Data folder.
After the site is built, the next step is to add a reference (reference) to your database in Visual Studio's Server Explorer. After you add a database to Server Explorer, you can add datasheets, stored procedures, views, and so on in the Visual Studio environment. You can also view the data in the database and create your own query by hand or by using the graphical interface of Query Builder (Builder). Also, when we create a strongly typed dataset for the DAL, we need to point Visual studio to the target database as the dataset data source. Although we can provide the database connection information involved in due course, Visual Studio automatically populates these databases in a Drop-down list if we register them in advance in Server Explorer.
The steps to add the Northwind database to Server Explorer depend on whether you want to use the SQL Server Express version database that is placed in the App_Data folder, or if you want to use the SQL Server 2000 or 2005 that you have built The database server.