ADO+管理器功能

2016-01-29 18:08 0 1 收藏

ADO+管理器功能,ADO+管理器功能

【 tulaoshi.com - ASP 】

 
  In the past, data access was done using a two-tiered, connected model. With the increased development of
multi-tiered applications, the need for a disconnected model has arisen. The ADO+ managed providers give
us this model.

Managed providers are responsible for creating connections between DataSet objects and data sources like
relational databases or XML documents. There are three main levels to the managed provider implementation:

Connections, Commands and Parameters are responsible for communication between DataSets and data sources.
The DataSetCommand actually retrieves the data and provides column and table mappings.
The DataReader provides high-speed, forward only access to data. Under the covers, the DataStream object
provides the direct connection to the data source.
Lower level objects connect to the specific data sources and provide the system specific commands.

At the center of the ADO+ model are the Connection, Command and DataSet objects. In this article I'm going
to focus on the Connection and Command objects. You can read more about the DataSet in my previous
article "ADO+ DataSets, Recordsets on Steroids?"

Two Ways to Connect

Why two managed providers? Microsoft has given us one provider for connecting directly to a SQL Server
database and one for accessing data via an OLE DB layer. The two Connection objects with which to connect
to data stores are: The SQLConnection for connecting to Microsoft SQL Server and the ADOConnection for
connecting via an OLE DB provider. The SQL managed provider can be used if you include the System.Data.SQL
namespace. To use the ADO managed provider, include the System.Data.ADO namespace. A connection can be
established the following two ways (in C#):

SQL

String sConnectionString = "server=localhost;uid=sa;pwd=;database=pubs";
SQLConnection con = new SQLConnection(sConnectionString);
con.Open();


csharpindex.com/colorCode

ADO

String sConnectionString = "Provider= SQLOLEDB.1;
Data Source=localhost;
uid=sa; pwd=; Initial Catalog=pubs";

ADOConnection con = new ADOConnection(sConnectionString);
con.Open();


csharpindex.com/colorCode

These two methods of opening a connection to a data source look remarkably similar, but let's take a
closer look. The connection string for the ADO managed provider should look very familiar to anyone who
has used ADO (it's identical). The SQLConnection supports a multitude of connection string keywords, but
the most common ones are server, uid, pwd and database. The first and last are obvious. The keywords uid
and pwd are just shortened versions of the database user id and password.

Execute A Statement

In order to get data from our data source, we need to execute commands against that data source. The
easiest way to do this is through either the ADO or SQL Command objects. Like this:

SQL

SQLCommand cmd = new SQLCommand(("SELECT * FROM Authors", con);
SQLDataReader dr = new SQLDataReader();
cmd.Execute(out dr);


csharpindex.com/colorCode

ADO

ADOCommand cmd = new ADOCommand("SELECT * FROM Authors", con);
ADODataReader dr = new ADODataReader();
cmd.Execute(out dr);


csharpindex.com/colorCode

In order to get to the data, we need to execute the command and put the data into a useable object like
the DataReader. For a more complete discussion of the DataReader objects, check out my first article about
data access with the ADO+ DataReader object.

Using Stored Procedures

Ok, so how about something a little more real world. Most of us use stored procedures to access data from
a database. Additionally, most of the time we need to pass parameters to these stored procedures. In the
example above, we get back a list of authors. Let's assume we want to see information about

来源:https://www.tulaoshi.com/n/20160129/1504503.html

延伸阅读
标签: 电脑入门
我们打开开始运行,输入 gpedit.msc 。 在本地组策略编辑器中,依次点击:用户配置管理模块系统Ctrl+Alt+Del选项,并双击右侧列表中的删除任务管理器 将删除任务管理器设置为未配置,即可解决任务管理器打不开与任务管理器被禁用的问题。
标签: 电脑 网络
第一步 首先打开电脑桌面的“开始”菜单,点击“运行’。 第二步 【运行】的窗口,输入”gpedit.msc“的命令,然后点击”确定“。 第三步 【组策略】的窗口,找到”用户配置“这一项。然后展开”用户配置“——管理模板——系统——找到Ctrl + Alt + Del。”Ctrl + Alt + Del“的右边Ctrl + Alt + Del选项中鼠标右...
标签: 电脑入门
资源管理器是大家熟悉和常用的Windows文件查看和管理工具,和之前的Windows版本相比,Win7的资源管理器提供了更加丰富和方便的功能,比如高效搜索框、库功能、灵活地址栏、丰富视图模式切换、预览窗格等等,可以有效帮助我们轻松提高文件操作效率。 按下快捷键Win+E就可以快速打开Win7资源管理器。Win7资源管理器窗口左侧的列表区包含收藏夹、...
RE文件管理器怎么用?   首先,用户在手机上安装了re管理器后,先打开re管理器中文版。 找到并打开文件system;再找到并打开文件app: 里面就是系统程序了,每个程序有两个文件,apk、odex,可以都删也可以保留apk放到sd卡里以后要了装,看你自己了: 接下来,卸载软件只需要将挂载转为读写就可以进行操作了,...
RE管理器怎么切换主题   RE管理器怎么切换主题?默认黑色主题如果让小伙伴觉得不喜欢可以根据需要自由更换主题颜色。在哪里切换呢?接下来小编就跟小编一起来看看RE管理器怎么切换主题? 1)打开RE管理器,点击下方,接着点击。 2)点击,接着根据需要选择主题即可。

经验教程

133

收藏

16
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部