微软企业库5.0
微软企业库需下载安装
1.添加引用
Microsoft.Practices.EnterpriseLibrary.Data;
Microsoft.Practices.EnterpriseLibrary.Common;
2.命名空间引用
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
3.配置 web.config文件
<add name="yoyo" connectionString="server=.;uid=sa;pwd=j;database=yoyo_jx" providerName="System.Data.SqlClient" />
4.写代码
Database db=DatabaseFactory.CreateDatabase("yoyo");
using (DbConnection con = db.CreateConnection())
{
DataSet ds = new DataSet();
string sql = string.Format("select top {0} * from youeryuan",10);
ds = db.ExecuteDataSet(CommandType.Text,sql);
foreach (DataRow dr in ds.Tables[0].Rows)
{
Response.Write(dr["name"].ToString());
}
}