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.
- ASP. NET 2.0 data Tutorial: insert, update, and delete data
- ASP. NET 2.0 data Tutorial: how to add parameterization to the data access layer
- ASP. NET 2.0 data Tutorial: create a data access layer
- ASP. NET 2.0 data Tutorial: create a Web project and configure database connection
- ASP. NET 2.0 data Tutorial: add field-level verification to DataRow