C# 数据适配器和数据读取器有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1139325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what is the difference between data adapter and data reader?
提问by Novice Developer
What is the difference between data adapter and data reader?
数据适配器和数据读取器有什么区别?
采纳答案by Andrew Hare
Please see DataReader, DataAdapter & DataSet - When to use? :
请参阅DataReader、DataAdapter 和 DataSet - 何时使用?:
ADO.NET provides two central Data Access Components. The excellent thing is that, they are common across all Databases, be it SQL Server or other competitive databases. Its only the namespace to be used, that differs, while using a Database other than SQL Server.
ADO.NET 提供了两个中心数据访问组件。最棒的是,它们在所有数据库中都是通用的,无论是 SQL Server 还是其他竞争数据库。它只是要使用的命名空间,在使用 SQL Server 以外的数据库时有所不同。
回答by John Saunders
A DataReader is an object returned from the ExecuteReader method of a DbCommand object. It is a forward-only cursor over the rows in the each result set. Using a DataReader, you can access each column of the result set, read all rows of the set, and advance to the next result set if there are more than one.
DataReader 是从 DbCommand 对象的 ExecuteReader 方法返回的对象。它是每个结果集中行上的只进游标。使用 DataReader,您可以访问结果集的每一列,读取该集的所有行,如果有多个结果集,则前进到下一个结果集。
A DataAdapter is an object that contains four DbCommand objects: one each for SELECT, INSERT, DELETE and UPDATE commands. It mediates between these commands and a DataSet though the Fill and Update methods.
DataAdapter 是一个包含四个 DbCommand 对象的对象:一个用于 SELECT、INSERT、DELETE 和 UPDATE 命令。它通过 Fill 和 Update 方法在这些命令和 DataSet 之间进行调解。
回答by Abhishek Dwivedi
Data reader is an object through which you can read a sequential stream of data. it's a forward only data wherein you cannot go back to read previous data. data set and data adapter object help us to work in disconnected mode. data set is an in cache memory representation of tables. the data is filled from the data source to the data set thro' the data adapter. once the table in the dataset is modified, the changes are broadcast to the database back thro; the data adapter.
数据读取器是一个对象,您可以通过它读取连续的数据流。这是一个仅向前的数据,您无法返回读取以前的数据。数据集和数据适配器对象帮助我们在断开连接的模式下工作。数据集是表的缓存内存表示。数据通过数据适配器从数据源填充到数据集。一旦数据集中的表被修改,更改就会广播到数据库中;数据适配器。
回答by Reema Gupta
DataReader
is a faster way to retrieve the records from the DB. DataReader
reads the column. DataReader
demands live connection but DataAdapter
needs disconnected approach.
DataReader
是从数据库中检索记录的更快方法。DataReader
阅读专栏。DataReader
需要实时连接但DataAdapter
需要断开连接的方法。
回答by Bhupat
Data Reader is an object used in connected Environment. Data Adapter is an object used in Disconnected environment using Dataset.
Data Reader 是连接环境中使用的对象。数据适配器是在使用数据集的断开连接环境中使用的对象。
回答by lakachew
DataAdapter
数据适配器
DataAdapter will acts as a Bridge between DataSet and database. This dataadapter object is used to read the data from database and bind that data to dataset. Dataadapter is a disconnected oriented architecture.
DataAdapter 将充当 DataSet 和数据库之间的桥梁。此数据适配器对象用于从数据库读取数据并将该数据绑定到数据集。Dataadapter 是一种面向断开连接的架构。
DataReader
数据读取器
DataReader is used to read the data from database and it is a read and forward only connection oriented architecture during fetch the data from database. DataReader will fetch the data very fast when compared with dataset. Generally we will use ExecuteReader object to bind data to datareader
DataReader 用于从数据库中读取数据,它是一种在从数据库中获取数据期间的面向连接的只读和转发架构。与数据集相比,DataReader 将非常快速地获取数据。一般我们会使用 ExecuteReader 对象将数据绑定到 datareader
回答by Jatin Phulera
DataReader
数据读取器
DataReader works only in forward direction means row read once cannot be read again because of this it is fast to fetching records. Datareader always required a Open connection for executing the SQL commands. Once a connection closed then you will not been able to read the data from datareader. Thats why it is used in connecte mode in SQL.
DataReader 仅在前向工作意味着无法再次读取行读取一次,因此获取记录的速度很快。Datareader 总是需要一个 Open 连接来执行 SQL 命令。一旦连接关闭,您将无法从 datareader 读取数据。这就是它在 SQL 中以连接模式使用的原因。
DatAdapter
数据适配器
DataAdapter gets all the returned rows from Sql statement at once and then fill the data into DataSet or datatable. Because of this dataadapter is slow in comparision to datareader. DataAdapter will not reuire any open and close connection . Means DataAdapter can work in Disconnected mode.
DataAdapter一次获取Sql语句返回的所有行,然后将数据填充到DataSet或datatable中。由于此数据适配器与数据读取器相比速度较慢。DataAdapter 不会要求任何打开和关闭连接。表示 DataAdapter 可以在断开连接模式下工作。
For more with example Read : - http://www.gurujipoint.com/2017/07/difference-between-dataadapter-and.html
更多示例阅读: - http://www.gurujipoint.com/2017/07/difference-between-dataadapter-and.html
回答by Tahir77667
Here is a nice article on the above topic: Difference Between DataReader, DataSet, DataAdapter and DataTable in C#
这是关于上述主题的一篇不错的文章: C# 中 DataReader、DataSet、DataAdapter 和 DataTable 的区别
Key differences in simple terms:
简单来说主要区别:
Unlike classic ADO, which was primarily designed for tightly coupled client/server systems,ADO.NET was built with the disconnected world in mind, using DataSets/DataAdapter.
Unlike classic ADO, which was primarily designed for tightly coupled client/server systems,ADO.NET was built with the disconnected world in mind, using DataSets/DataAdapter.
DataAdapter
follows connectionless-oriented architecture which simply means you need not necessarily be connected to a data-source whereasDataReader
is a connection-oriented architecture which means it needs an active connection to a data-source for it to operate.DataAdapter
is an intermediate layer/ middleware which acts a bridge between the DataSet and a Database whereasDataReader
provides forward-only, read-only access to data using a server-side cursor (simply put it is ued to read the data).- Using
DataSet
we can manipulate and update aDataSet's
contents while disconnected from the Datasource and send any modified data back for processing using a relatedDataAdapter
whereasDataReader
can only read data from a Database & cannot modify it. DataAdapter
object is used to read the data from database and populates that data toDataSet
whereasDataReader
simply reads the data using theRead() method
.DataAdapter
is comparatively slower whereas usingDataReader
can increase application performance both by retrieving data as soon as it is available, and (by default) storing only one row at a time in memory, reducing system overhead.
DataAdapter
遵循面向无连接的体系结构,这仅意味着您不必连接到数据源,而DataReader
面向连接的体系结构意味着它需要与数据源的活动连接才能运行。DataAdapter
是一个中间层/中间件,它充当数据集和数据库之间的桥梁,同时DataReader
使用服务器端游标提供对数据的只进、只读访问(简单地说,它用于读取数据)。- 使用
DataSet
我们可以DataSet's
在与数据源断开连接的情况下操作和更新内容,并将任何修改过的数据发回使用相关的处理,DataAdapter
而DataReader
只能从数据库中读取数据而不能修改它。 DataAdapter
object 用于从数据库中读取数据并将该数据填充到其中,DataSet
而DataReader
只是使用Read() method
.DataAdapter
相对较慢,而 usingDataReader
可以通过在数据可用时立即检索数据以及(默认情况下)一次仅在内存中存储一行来提高应用程序性能,从而减少系统开销。