替代Microsoft数据访问ApplicationBlocks过时把SqlHelper类数据、Microsoft、SqlHelper、ApplicationBlocks

2023-09-04 12:03:30 作者:①苆嘟佷徦

看起来从微软企业库老把SqlHelper类 一直主要由包含在新的企业库5.0版本的数据库类取代。

It looks that the old SqlHelper class from the Microsoft Enterprise Library has been mostly replaced by the Database class which is included in the new Enterprise Library version 5.

我有一个非常简单的小例子:

I have a very simple and trivial example:

using Microsoft.ApplicationBlocks.Data;

private void PopulateCheckBoxGroup()
 {
     const string strConnTxt = "Server=(local);Database=DataBindTests;Integrated Security=True;";
     const string strlSql = "select Technology from PreferredTechnology where ParentId = 1";
     CheckBoxList1.DataSource = SqlHelper.ExecuteReader(strConnTxt, CommandType.Text, strlSql);
     CheckBoxList1.DataTextField = "Technology";
     CheckBoxList1.DataBind();

 }

你能给我只是一个提示,以便使用替代的提供SQLHelper新的数据库抽象类做的一样吗? 我研究过企业库5手把手实验室,并没有提到这件事。

Can you give me just a hint in order to do the same using the new Database abstract class that replaced the SQLHelper? I have looked into the Enterprise Library 5 "Hands On Labs" and there is no mention about it.

在此先感谢。

推荐答案

这是pretty的大致相同,只是在不同的建筑,如:

It's pretty much the same, just varies in its construction, e.g.:

var database = new SqlDatabase("<connection>");
using (var reader = database.ExecuteReader(...))
{

}