当前位置: 首页 > news >正文

微网站建设微网站建设程序员帮忙做放贷网站

微网站建设微网站建设,程序员帮忙做放贷网站,wordpress 汽车租赁,wordpress文章 页面模板下载前言 鉴于企业库5.0已经发布正式版#xff0c;同时有广大读者的要求#xff08;臭屁一下#xff0c;o(∩_∩)o...#xff09;#xff0c;后面文章的内容和代码将基于Enterprise Library5.0和Unity2.0来写#xff0c;感谢大家的一贯支持。 正文 数据库访问模块都能实现哪些…  前言   鉴于企业库5.0已经发布正式版同时有广大读者的要求臭屁一下o(∩_∩)o...后面文章的内容和代码将基于Enterprise Library5.0和Unity2.0来写感谢大家的一贯支持。   正文   数据库访问模块都能实现哪些功能呢数据库访问模块抽象类你正在使用的数据库提供了一些列接口使得你可以更容易的实现常用的数据库访问功能。例如:使用Database类填充DataSet数据集用database类获取一个适当的Command实例然后调用database的ExecuteDataSet方法就可以填充数据集。不需要你调用DataAdapter的Fill方法。ExecuteDataSet方法管理数据库连接实现了填充数据集所需要的所有工作。使用类似的方法通过database类可以直接执行command可以获取一个DataReader实例可以用dataset中的数据更新数据库。模块也支持多个操作的事务如果失败的话可以回滚。   除了使用ADO.NET也能完成的常用功能以外模块还支持异步访问数据库只要数据支持。还可以返回客户端可以用LINQ查询的数据的序列对象形式。   使用数据访问模块的主要优点除了简化开发以外它使得你可以创建一种provider独立的应用可以很容易的更换不同的数据提供源。在大多数情况下除非你在代码中指定了数据库类型剩下的就是更改配置文件中的连接字符串配置节就可以了。不需要你修改代码中的sql查询和存储过程及其参数。   数据访问模块提供的常用方法   下面列出一些模块常用的获取数据、更新数据方法其中有一些和直接使用ADO.NET中的方法很相似。      方法 功能 ExecuteDataset创建加载返回数据集 LoadData加载数据到一个已经存在的数据集 UpdateDataSet使用已经存在的数据集更新数据库内容 填充一个数据集使用数据集更新数据库 ExecuteReader创建返回一个provider独立的DbDataReader实例 从数据库读取多行数据 ExecuteNonQuery执行command返回数据库受影响的行数可以通过output返回多个值 ExecuteScalar执行command返回单个值 执行command数据库命令对象 ExecuteSproAccessor使用存储过程返回一个客户端可以查询的序列对象 ExecuteSqlStringAccessor使用SQL语句返回一个客户端可以查询的序列对象 以序列对象的形式返回数据 ExecuteXmlReader返回xml格式的数据xmlReader类型这个只能用在SQL Server数据库通过SqlDatabase类调用Database类中没有这个方法。 获取xml格式数据只能用在SQL Server数据库 GetStoredProcCommand返回一个存储过程的数据库command对象 GetSqlStringCommand返回一个SQL语句的数据库command对象 创建一个Command对象 AddInParameter创建一个新的input参数并且加入command的参数集合 AddOutParameter创建一个新的output参数并且加入command的参数集合 AddParameter创建一个指定类型的参数并且加入command的参数集合 GetParameterValue以Object类型返回指定参数的值 SetParameterValue给指定参数赋值   处理command的参数 CreateConnection创建返回当前数据库的连接允许你通过这个链接初始化和管理数据库事务 处理数据库事务        如果你使用SqlDatabase类的话可以使用Begin和End类型的方法实现数据库异步操作。       如何使用数据库访问模块       1首先通过企业库的配置工具添加模块配置       2在代码中添加如下代码         代码 static Database defaultDB  null;static Database namedDB  null;// 从容器中获取默认的数据库对象// The actual concrete type is determined by the configuration settings.defaultDB  EnterpriseLibraryContainer.Current.GetInstanceDatabase();// 从容器中获取指定名称的数据库对象 namedDB EnterpriseLibraryContainer.Current.GetInstanceDatabase(ExampleDatabase);          如果你需要使用ExecuteXmlReader方法或者是需要使用SQL Server数据库对象的话可以用下面的代码。   代码 static SqlDatabase sqlServerDB  null;// Resolve a SqlDatabase object from the container using the default database.sqlServerDB  EnterpriseLibraryContainer.Current.GetInstanceDatabase()as SqlDatabase;// Assume the method GetConnectionString exists in your application and// returns a valid connection string.string myConnectionString  GetConnectionString();SqlDatabase sqlDatabase  new SqlDatabase(myConnectionString);         使用DataReader获取多行数据   代码 // Call the ExecuteReader method by specifying just the stored procedure name.using (IDataReader reader  namedDB.ExecuteReader(MyStoredProcName)){// Use the values in the rows as required.}// Call the ExecuteReader method by specifying the command type// as a SQL statement, and passing in the SQL statement.using (IDataReader reader  namedDB.ExecuteReader(CommandType.Text,SELECT TOP 1 * FROM OrderList)){// Use the values in the rows as required ‐ here we are just displaying them.DisplayRowValues(reader);}         根据参数获取多行数据         代码 using (IDataReader reader  defaultDB.ExecuteReader(ListOrdersByState,new object[] { Colorado })){// Use the values in the rows as required ‐ here we are just displaying them.DisplayRowValues(reader);}                     通过添加参数获取多行数据 代码 // Read data with a SQL statement that accepts one parameter.string sqlStatement  SELECT TOP 1 * FROM OrderList WHERE State LIKE state;// Create a suitable command type and add the required parameter.using (DbCommand sqlCmd  defaultDB.GetSqlStringCommand(sqlStatement)){defaultDB.AddInParameter(sqlCmd, state, DbType.String, New York);// Call the ExecuteReader method with the command.using (IDataReader sqlReader  namedDB.ExecuteReader(sqlCmd)){Console.WriteLine(Results from executing SQL statement:);DisplayRowValues(sqlReader);}}               代码 // Create a suitable command type and add the required parameter.using (DbCommand sprocCmd  defaultDB.GetStoredProcCommand(storedProcName)){defaultDB.AddInParameter(sprocCmd, state, DbType.String, New York);// Call the ExecuteReader method with the command.using (IDataReader sprocReader  namedDB.ExecuteReader(sprocCmd)){Console.WriteLine(Results from executing stored procedure:);DisplayRowValues(sprocReader);}}         以对象形式返回数据             上图是一个使用Accessor访问数据库返回对象形式的数据的过程。 未完待续。。。。。。。。。。。。。。。。。。。。。。。。  转载于:https://www.cnblogs.com/virusswb/archive/2010/05/14/Enterprise-Library-DataAccessBlock-3.html
http://wiki.neutronadmin.com/news/12778/

相关文章:

  • 大连建网站需要多少钱有了源码该怎么建立app
  • 潍坊网站建设联系方式网站为什么被挂马
  • 最新免费下载ppt模板网站网站添加地图导航
  • 如何建立自己的微网站哪里有做网站平台
  • 國家建设协会官方网站哪一个网站可以做任务拿佣金
  • 口碑好的聊城网站建设上海网站建设公司服务怎么做
  • 哪些网站教你做美食的网络科技公司骗术
  • 养生网站源码下载做好的网站如何上线
  • 康体设备网站建设昆明市建设局网站
  • 广东专业做网站排名公司哪家好重庆招生院校网站
  • 黄山网站设计太原搭建网站的公司
  • 关于推广网站的标题安徽网络公司排名
  • 牡丹江0453免费信息网站网站备案后可以修改吗
  • 花钱做的网站本人可以关闭吗公司名称变更网上核名怎么弄
  • 个人做 网站2019俄罗斯做牙网站
  • 网站建设规划书有哪些内容互联网行业怎么样
  • 怎么看网站室哪做的青岛 网站开发
  • 学校官方网站网页设计wordpress怎么卸载主题
  • 东莞营销型网站建设找火速美剧网站怎么做
  • 企业网站建设发展平台怎么样查询建设网站
  • 电子商务网站建设网站电子版没营业执照怎么做网站
  • 静态网站开发项目实验报告免费建站网站哪个好
  • 建设银行新加坡招聘网站黑龙江做网站的公司有哪些
  • 做外贸生意是不是需要建网站什么是网络营网络营销的特点
  • 专业做鞋子的网站wordpress 主题 ie6
  • 国内网站建设wordpress企业中文主题
  • 个人网站页面上海做网站 公司 哪家好
  • 网站更换模板seo的理解
  • 网站建设工资多少wordpress导航栏该怎么设置
  • 房城乡建设部门户网站网站建设公司唯美谷