Download the Enterprise Library: (there are related videos and help documents) entlib. codeplex. comEntlib5.0 requirements. netframework3.5sp1, or. netframework4.0App. config :? Xmlversion1.0encodingutf-8? ConfigurationconfigdivsdivnamedataConfigurationtypeMicro
Enterprise Library download: (there are related video and help documentation) http://entlib.codeplex.com/Entlib5.0 requirements. net framework3.5 sp1, or. net framework 4.0 App. config :? Xml version = "1.0" encoding = "UTF-8 "? Configuration configps p name = "dataConfiguration" type = "Micro
Download Enterprise Library: (there are related videos and help documents)
Http://entlib.codeplex.com/
Entlib5.0 requires. net framework3.5 sp1, or. net framework 4.0
App. config:
Using System; using System. collections. generic; using System. linq; using System. text; using Microsoft. practices. enterpriseLibrary. data; using Microsoft. practices. enterpriseLibrary. data. SQL; using System. data. common; using System. data; namespace TestEntLib5_0InFramework3_5 {class Program {static void Main (string [] args) {Database db = DatabaseFactory. createDatabase (); // create a default Database object // Database db = DatabaseFactory. createDatabase ("DbConnString182"); // create a named database object // 1. executeNonQuery/* DbCommand dbCmd = db. getSqlStringCommand (@ "insert into T_EntLib (name, birthday, email) VALUES (N 'wu 1', '2017-12-23 ', 'a @ qq.com '); insert into T_EntLib (name, birthday, email) VALUES (N 'wu 2', '2017-12-23 ', 'gga @ qq.com'); insert into T_EntLib (name, birthday, email) VALUES (N 'wu 3', '2017-12-23 ', 'a @ qq.com'); insert into T_EntLib (name, birthday, email) VALUES (N 'wu 4', '2017-12-23 ', 'a @ qq.com'); insert into T_EntLib (name, birthday, email) VALUES (N 'wu 5 ', '2017-12-23 ', 'a @ qq.com'); "); int iAffectedNum = db. executeNonQuery (dbCmd); // return the number of affected items. writeLine (iAffectedNum); * // 2. executeDataSet automatically enables and disables Connection // var SQL = "select top 10 * FROM sys_draw order by id DESC";/* var SQL = "SELECT * FROM T_EntLib"; DbCommand cmd = db. getSqlStringCommand (SQL); // No need to open the connection; just make the call. // monitoring during execution: cmd. connection. state DataSet ds = db. executeDataSet (cmd); // found here: cmd. connection. stateClosedSystem. data. connectionState // indicates that the connection to the Console is automatically disabled. writeLine (ds. tables [0]. rows. count); int col = ds. tables [0]. columns. count; foreach (DataRow dr in ds. tables [0]. rows) {for (int I = 0; I <col; I ++) {Console. write (dr [I]. toString ();} Console. writeLine ();} * // 3: ExecuteReader/*** If the Data Access Application Block methods close the connection before returning the DbDataReader, * the DbDataReader becomes useless to the client code. instead, the DbDataReader methods indicate * to the underlying ADO. NET call to automatically close the connection when the DbDataReader is disposed. * ** // * var SQL = "SELECT * FROM T_EntLib"; DbCommand cmd = db. getSqlStringCommand (SQL); using (IDataReader reader = db. executeReader (cmd) {int col = reader. fieldCount; while (reader. read () {for (int I = 0; I <col; I ++) {Console. write (reader [I]. toString ();} Console. writeLine () ;}// after this, cmd is found. connection. the State is automatically changed to Closed. * // 4: Retrieving Data as Objects var SQL = "SELECT * FROM T_EntLib"; // var result = db. executeSqlStringAccessor
(SQL); // use the default RowMapper IRowMapper <Info> rowMapper = MapBuilder
. MapAllProperties (). mapByName (x => x. NAME ). doNotMap (x => x. email ). doNotMap (x => x. birthday ). build (); var result = db. executeSqlStringAccessor
(SQL, rowMapper); // use the custom RowMapper foreach (var item in result) {Console. writeLine ("ID = {0}, Name: {1}, Birthday: {2}, Email: {3}", item. id, item. NAME, item. birthday, item. email);} Console. readKey ();}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace TestEntLib5_0InFramework3_5{ public class Info { public int Id { get; set; } public string NAME { get; set; } public string Email { get; set; } public DateTime Birthday { get; set; } }}
CREATE TABLE T_EntLib(ID bigint IDENTITY,NAME nvarchar(50),Birthday datetime,Email varchar(50))
Http://files.cnblogs.com/wucg/TestEntLib5_0InFramework3_5.zip