|
ADO.NET includes many objects you can use to work with data. This section introduces some of the primary objects you will use. Over the course of this tutorial, you''''ll be exposed to many more ADO.NET objects from the perspective of how they are used in a particular lesson. The objects below are the ones you must know. Learning about them will give you an idea of the types of things you can do with data when using ADO.NET.
ADO.NET包括许多你用来和数据打交道的对象。这一节介绍了一些你将使用的主要对象。本指南结束后,你将会在专门的课程中学习到更多的ADO.NET对象。下面的对象是必须了解的。学习它们能够在使用ADO.NET的时候让你了解和数据打交道会考虑哪些事情。
The SqlConnection Object
SqlConnection 对象
To interact with a data base, you must have a connection to it. The connection helps identify the data base server, the data base name, user name, password, and other parameters that are required for connecting to the data base. A connection object is used by command objects so they will know which data base to execute the command on.
和数据库交互,你必须连接它。连接帮助指明数据库服务器、数据库名字、用户名、密码,和连接数据库所需要的其它参数。connection对象会被command对象使用,这样就能够知道是在哪个数据库上面执行命令。
The SqlCommand Object
SqlCommand 对象
The process of interacting with a data base means that you must specify the actions you want to occur. This is done with a command object. You use a command object to send SQL statements to the data base. A command object uses a connection object to figure out which data base to communicate with. You can use a command object alone, to execute a command directly, or assign a reference to a command object to an SqlDataAdapter, which holds a set of commands that work on a group of data as described below.
与数据库交互的过程意味着你必须指明想要发生的操作。这是依靠command对象执行的。你使用command对象来发送SQL语句给数据库。command对象使用connection对象来指出与哪个数据库进行连接。你能够单独使用command对象来直接执行命令,或者将一个command对象的引用传递给SqlDataAdapter,它保存了一组能够操作下面描述的一组数据的命令。
The SqlDataReader Object
sqlDataReader对象
Many data operations require that you only get a stream of data for reading. The data reader object allows you to obtain the results of a SELECT statement from a command object. For performance reasons, the data returned from a data reader is a fast forward-only stream of data. This means that you can only pull the data from the stream in a sequential manner. This is good for speed, but if you need to manipulate data, then a DataSet is a better object to work with.
许多数据操作要求你只是读取一串数据。data reader对象允许你获得从command对象的SELECT语句得到的结果。考虑性能的因素,从data reader返回的数据都是快速的且只是“向前”的数据流。这意味着你只能按照一定的顺序从数据流中取出数据。这对于速度来说是有好处的,但是如果你需要操作数据,更好的办法是使用DataSet。
The DataSet Object
DataSet对象
DataSet objects are in-memory representations of data. They contain multiple DataTable objects, which contain columns and rows, just like normal data base tables. You can even define relations between tables to create parent-child relationships. The DataSet is specifically designed to help manage data in memory and to support disconnected operations on data, when such a scenario make sense. The DataSet is an object that is used by all of the Data Providers, which is why it does not have a Data Provider specific prefix.
DataSet对象是数据在内存中的表示形式。它包括多个DataTable对象,而DataTable包含列和行,就象一个普通的数据库中的表。你甚至能够定义表之间的关系来创建主从关系(parent-child relationships)。DataSet是在特定的场景下使用――帮助管理内存中的数据并支持对数据的断开操作的。DataSet是被所有Data Providers使用的对象,因此它并不像Data Provider一样需要特别的前缀。
The SqlDataAdapter Object
SqlDataAdapter对象
Sometimes the data you work with is primarily read-only and you rarely need to make changes to the underlying data source. Some situations also call for caching data in memory to minimize the number of data base calls for data that does not change. The data adapter makes it easy for you to accomplish these things by helping to manage data in a disconnected mode. The data adapter fills a DataSet object when reading the data and writes in a single batch when persisting changes back to the data base. A data adapter contains a reference to the connection object and opens and closes the connection automatically when reading from or writing to the data base. Additionally, the data adapter contains command object references for SELECT, INSERT, UPDATE, and DELETE operations on the data. You will have a data adapter defined for each table in a DataSet and it will take care of all communication with the data base for you. All you need to do is tell the data adapter when to load from or write to the data base.
某些时候你使用的数据主要是只读的,并且你很少需要将其改变至底层的数据源。同样一些情况要求在内存中缓存数据,以此来减少并不改变的数据被数据库调用的次数。Data adapter通过断开模型来帮助你方便的完成对以上情况的处理。当在一单批次的对数据库的读写操作的持续的改变返回至数据库的时候,Data adapter 填充(fill)DataSet对象。data adapter包含对连接对象以及当对数据库进行读取或者写入的时候自动的打开或者关闭连接的引用。另外,data adapter包含对数据的SELECT,INSERT,UPDATE和DELETE操作的command对象引用。你将为DataSet中的每一个table都定义data adapter,它将为你照顾所有与数据库的连接。所有你将做的工作是告诉data adapter什么时候装载或者写入到数据库。
Summary
总结
上一页 [1] [2] [3] [4] 下一页 [C语言系列]NET 中C#的switch语句的语法 [系统软件]托拽Explore中的文件到VB.net的窗口 [系统软件]Boost库在XP+Visual C++.net中的安装 [常用软件]新配色面板:Paint.Net3.0RC1官方下载 [常用软件]用内建的“Net Meeting”聊天 [VB.NET程序]Henry的VB.NET之旅(三)—共享成员 [VB.NET程序]Henry的VB.NET之旅(二)—构造与析构 [VB.NET程序]Henry的VB.NET之旅(一)—失踪的窗体 [VB.NET程序]在托盘上显示Balloon Tooltip(VB.NET) [VB.NET程序]Henry手记-VB.NET中动态加载Treeview节点(二)
|