Substitute for Microsoft Data Access ApplicationBlocks obsolete SqlHelper class

空扰寡人 提交于 2020-01-03 18:18:33

问题


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();

 }

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.

thanks in advance.


回答1:


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

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

}


来源:https://stackoverflow.com/questions/4464874/substitute-for-microsoft-data-access-applicationblocks-obsolete-sqlhelper-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!