Enterprise Library 4.0 Data Access Application Block Configuration

Source: Internet
Author: User

Version: 4.0

: Http://www.microsoft.com/downloads/thankyou.aspx? Familyid = 90de37e0-7b42-4044-99be-f8ecfbbc5b65 & displaylang = en

Video address: http://www.msdnwebcast.com/webcasts/net.aspx/ctech/n1242188.html

 

This article includes the following content:

1. Introduction

2. Installation

3. Configuration

4. Use

 

I. Introduction

Enterprise Library is a group of applications.ProgramEach application block is designed to address one aspect of developing enterprise-level applications. It can improve the maintainability and scalability of enterprise-level applications, maximize reuse, can be used as the company's accumulation, build more elegant and flexible enterprise-level applications, open source, Microsoft's benchmarkCode, You can learnSource codeTo improve programming capability.

Composition and dependency:

Ii. Installation

Download the installation package and run it. After the installation is completed based on the wizard step by step, restart Visual Studio to see that the configuration tool has been integrated into IDE. (Right-click the website configuration file)

 

After installation, a message is displayed, indicating whether to compile the project. Select Yes. If it is installed by default, after the installation is complete, the DLL of all components is displayed under the system drive letter \ Program Files \ Microsoft Enterprise Library 4.0-May 2008 \ bin.

Iii. Configuration

Right-click Web. config and select Edit Enterprise Library configuration to add the database connection string:

 

Save the edited content. Next, modify web. config and add the following code: <dataconfiguration defaultdatabase = "connectionstring"/>.
 

 

 

Note: The defaultdatabase value is a name value in connectionstrings. If you do not specify the default database connection, you must callCreatedatabase ()The constructor with parameters, that is, the value of the name of the database connection to be used.

Iv. Use

First, add reference:

 

Then the using namespace

Using Microsoft. Practices. enterpriselibrary. Data;
Using Microsoft. Practices. enterpriselibrary. Common;
Using System. Data. Common;
Using System. Data;

Encoding Demo:

Dataset DS =   New Dataset ();
Database DB = Databasefactory. createdatabase ();
DS = DB. executedataset (commandtype. Text,
" Select * from product " );
Gridview1.datasource = DS. Tables [ 0 ];
Gridview1.databind ();

 

Dataset DS =   New Dataset ();
Database DB = Databasefactory. createdatabase ();
DS = DB. executedataset ( " Selproductbyclasscode " , " 10 " );
Gridview1.datasource = DS. Tables [ 0 ];
Gridview1.databind ();

 

Dataset DS =   New Dataset ();
Database DB = Databasefactory. createdatabase ();
Dbcommand cmd =
DB. getstoredproccommand ( " Selproductbyclasscode " );
DB. addinparameter (CMD, " Classcode " , Dbtype. string, " 10 " );
DB. addinparameter (CMD, " ID " , Dbtype. int32, 1 );
DS = DB. executedataset (CMD );
Gridview1.datasource = DS. Tables [ 0 ];
Gridview1.databind ();

Database has some methods with the same name and function as sqlcommand. Let's draw a line from each other.

 

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.