ASP. NET 2.0 data Tutorial: Add a method for TableAdapter

Source: Internet
Author: User

In our first example, we need to add a method to obtain the employees who employ the date HireDate) in a specified month. To provide this function in our program architecture, we first need to create a method in the EmployeesTableAdapter mapped out through a specific SQL statement. To achieve this, first open the Northwind type dataset and right-click the EmployeesTableAdapter tab and select "add query ".

 

Figure 2: Add a query in the EmployeesTableAdapter

Select the SQL statement that returns one or more rows and columns. When the window of the specified SELECT statement is reached, the default SELECT statement is mounted on the EmployeesTableAdapter. Simply add a WHERE clause: where datepart (m, HireDate) = @ Month. Where DATEPART is a function in the T-SQL that is used to return part of the date type; here we use the DATEPART function to return the month portion of the hire date HireDate column.

 

Figure 3: only the rows whose values in the HireDate column are less than or equal to @ HiredBeforeDate are returned.

Finally, change the default method names FillBy and GetDataBy to FillByHiredDateMonth and GetEmployeesByHiredDateMonth respectively.

 

Figure 4: select a method name that is more appropriate than FillBy and GetDataBy

Click "finish" to end the wizard and return to the dataset design page. At this time, the EmployeesTableAdapter will include a new method to obtain the employees hired in the specified month.

 

Figure 5: The new method appears on the dataset design page.

  1. ASP. NET 2.0 data Tutorial: insert, update, and delete data
  2. ASP. NET 2.0 data Tutorial: how to add parameterization to the data access layer
  3. ASP. NET 2.0 data Tutorial: create a data access layer
  4. ASP. NET 2.0 data Tutorial: create a Web project and configure database connection
  5. ASP. NET 2.0 data Tutorial: add field-level verification to DataRow

Related Article

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.