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?
问题:
回答1:
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
回答2:
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.