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.