Difference between DataSource and DataSet

2019-06-18 04:44发布

I am currently working on project whose main task is to read data stored in SQL database and to display them in user-friendly form. Programming language used is C++. I am working in Borland C++ Builder 6 environment. But I think question posed in title is independent from programming language or libraries. When reading data from db i am quite frequently meeting with these terms in class names without knowing exactly what they represent. I understand that they behave as interface to data stored in db. But why there is need to use two interface classes instead of one?

2条回答
ら.Afraid
2楼-- · 2019-06-18 05:28

Assuming you are talking about the .NET ecosystem, these two terms mean very different things.

A DataSet is a class representing relational data in the process memory (that is, outside the database) - normally populated from a database. It represents tables and relationships between them (say foreign key constraints).

DataSource is an attribute in data binding - assigning an object to a control on the DataSource property binds a source of data (such as a DataSet) to a control.

查看更多
够拽才男人
3楼-- · 2019-06-18 05:31

DataSource = How you connect to your database DataSet = Structure of your database in memory

More in details (from the Exam 70-516: TS: Accessing Data with Microsoft .NET Framework 4 book):

DataSource This is the primary property to which you assign your data. You can assign anything that implements the IList, IListSource, IBindingList, or IBindingListView interface. Some examples of items that can be assigned to the DataSource property are arrays (IList), lists (IList), data tables (IListSource), and data sets (IListSource).

DataSet is a memory-based, tabular, relational representation of data and is the primary disconnected data object. Conceptually, think of DataSet as an in-memory relational database, but it’s simply cached data and doesn’t provide any of the transactional properties (atomicity, consistency, isolation, durability) that are essential to today’s relational databases. DataSet contains a collection of DataTable and DataRelation objects

查看更多
登录 后发表回答