ASP.net 2.0 implementing the data Access layer

Source: Internet
Author: User

1. Implementing the data Access layer

This section describes the implementation of the data access layer, which includes all the necessary classes and methods for communicating with the AdventureWorks database. First, create a new Visual C # class Library project adventureworkstraderdataaccess using Visual Studio 2005. When this project is created, you can modify the default class name to Productcategorydb. Example 1 illustrates the implementation code for the Productcategorydb class.

Example 1: Implementing the Productcategorydb Class

Using System;
Using System.Data;
Using System.Data.Common;
Using System.Data.SqlClient;
Using System.Collections.Generic;
Using System.Text;
Using Adventureworkstraderentities;
Using Microsoft.Practices.EnterpriseLibrary.Data; Namespace Adventureworkstraderdataaccess {public class Productcategorydb {private datacolumnmapping[] mappings = new Dat Acolumnmapping[] {new DataColumnMapping ("ProductCategoryID", "ProductCategoryID"), new DataColumnMapping ("Name", "
Name "), new DataColumnMapping (" Rowguid "," rowguid "), new DataColumnMapping (" ModifiedDate "," ModifiedDate ")}; Public ilist〈productcategory> getproductcategories () {ilist〈productcategory> list = new List〈productcategory
> ();
Database db = Databasefactory.createdatabase ();
String storedprocedurename = "Getproductcategories"; DbCommand DbCommand = db.
Getstoredproccommand (StoredProcedureName); using (IDataReader reader = db. ExecuteReader (DbCommand)) {while reader.
Read ()) {ProductCategory temp = new ProductCategory (); ProdUctcategory category = (productcategory) dataaccesshelper.populateentity (temp, mappings, reader); List.
ADD (category);
} return list; }
}
}

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.