ASP. net2.0 getting started Chapter 1 Architecture Design 2

Source: Internet
Author: User

Later, we will build a data access layer Dal. Friends who are learning ASP. net2.0 at the beginning may be unfamiliar with this. What is Dal? What does it do?
For example, if you go to a small store to buy things, you need to select products (these products are similar to data). They are on shelves (shelves are databases), but they are not supermarkets, you cannot get the product you need directly. You must use a salesperson (comparing him to Dal) to help you take the goods as an agent. And show you the products you want to view.

In many cases, we can use other methods to present data, such as sqldatasoucer. However, you may need to return more data, for example, you want to display 100 tables with different content, you need to use 100 sqldatasoucer to complete this job. If you define all this work in the data access layer, you only need to create a data access layer, it contains the methods for querying, inserting, deleting, and updating all tables.

Section 2: create a data access layer
1. Basic Data Query
Design intent :
We have created a database, and in the following process we need to query, or modify and add data in the database. Then, we need an intermediate layer as a proxy to access the database. In the past, it may have to be a lot written. Code But fortunately, in ASP. net2.0, we can simply complete this complex task without writing code, just a few simple SQL statements.
Work with me :
On the Solution tab, right-click the website directory title, add a new project, select a dataset, and name it bgset. XSD.

Then, follow the system prompts to select the default settings. In this window, select the database you just created from the drop-down list.
Follow the next step in the Wizard to enter the SQL statement. Select the query generator to automatically generate the SQL statement. First, select the player table.

Field names in all tables selected

The return and fill methods are as follows:

Well, this return method getplayer can return a datatable and bind data in the control. This method does not require the input of parameters, that is, it will return the values in all player tables.
2. query data with Parameters
Design intent However, many times we need to enter a specific parameter and get a specific data. For example, I only want to know the data of players whose ID is 3, so we can add a specific query
Work with me :
After adding a query, we can see a new method in the dataset. Right-click the method and choose add query.

Add the SQL statement "where (playerid = @ playerid)" to the last sentence.

Then follow the new naming method
Click Finish
Code omitted : You can complete other queries by yourself.
Player data returned by depid
Player data returned by POS
Code download : Dal Layer

3. Call methods in the user interface layer to query data
Design intent: Use the method just created in dal and display the obtained data in girdview.
Work with me:
Double-click default. in aspx, We will test the query method, switch to the design view, select the data-girdview control from the toolbar on the left, drag and drop it to the design view, and click the small triangle in the upper right corner of girdview, select "new data source" from the data source selection page"

Select the data source type and select "object"
In the define data method, select the getplayer () method and click Finish.
Click "start debugging". In the displayed dialog box, select Yes. The system automatically creates a web. config debugging file.
If the preceding steps are correct, the following table is displayed:

Code omitted : Other data query outputs are described in the following chapters, for example, if you are interested in outputting the data of a specified ID player, you can try it yourself.
The content of this section ends here.
if you have any unclear meanings, please help me out. Thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.