What are the best practices for using, and differences of, DataSet, DataView and DataTable?

Lenny Gray
Lenny Gray used Ask the Experts™
on
I have been a programmer since 1968 and I am learning VS2015 VB.NET. I have read three solid books on the subject and am writing code as an exercise to learn this VB.NET language.

After making the connection and creating an adapter to read the data, Then, I believe that the next step is to populate the dataset object.

Some books then suggest creating a DataView or DataTable. Some just work with the dataset. I am an MSDN subscriber/partner but their write-ups leave a lot to be desired at times.

What is the difference between the three? What are the conditions that you would use one over the other?

I will follow-up with another question so that you can get more points.

Thanks, in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Retired
Distinguished Expert 2017
Commented:
To your question, "What is the difference between the three?".
A DataSet is a container which holds one or more DataTable and can store relationships between multiple DataTables, these relationships are manually setup in the DataSet.
A DataTable is a container that holds data from a data source.
A DataView can be customized to show a subset of the data from the DataTable object. It allows you to have two controls bound to the same DataTable, but that show different versions of the same data.

To your question, "What are the conditions that you would use one over the other?", Any one of the three are NOT replacements for the others. For example if you only have data from one source you would not need to use a DataSet although you can still use it if you wanted. Also if you do not need to modify the default view then you would not need to create a custom view  but if you wanted to change the default view then you would or if you wanted to show the same data source in two or more controls differently.
In any case you will always need a DataTable because it is the container that holds the data.

Author

Commented:
Fernando, you are a natural teacher.

I am grateful for your explanation. It was really clear.

Lenny
Fernando SotoRetired
Distinguished Expert 2017

Commented:
Not a problem Lenny, glad I was able to help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial