Link to home
Start Free TrialLog in
Avatar of dearb0ys
dearb0ys

asked on

DataSet

How to use the dataset in c# to retrieve data.
Avatar of Timbo87
Timbo87

Where are you getting the data from? SQL, Access, Excel, XML, or other?
Avatar of dearb0ys

ASKER

Access
ASKER CERTIFIED SOLUTION
Avatar of Timbo87
Timbo87

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi dearb0ys,

Actually a Dataset is not used to "retrieve data". A dataset is a in-memory representation of data grouped by tables. You will have to "fill" the tables inside the dataset with data. It's common to query a database and use that data, but you could also do it programaticly, reading an XML, a web service, a text file, etc... When reading from databases, you usually use Commands (SqlCommand, OleDBCommand, etc...). Timbo postes an example with an OleDbDataAdapter, that is an utility class that use up to 4 commands (1 for insert, 1 for update, 1 for delete and 1 for select). A dataAdapter is really useful to update the database, as it provides an Update method that will inspect the state of each row in a dataset's table and execute the correct command.

It's a good practice to use datasets in appropiates scenarios like:
1.- You have several tables related with each other, and you need to access parent or child rows
2.- You have different sources of data that can be related.
3.- You want to work in an disconnected enviroment and take advantage of a DataAdapter functionality.

It would be a bad choice to use a dataset in scenarios like:
1.- You have only one table that you want to bind to a control (Use a DataTable instead)
2.- You have very dynamic data that force you to rebuild the dataset often (Use DataReaders instead)

I suggest you to look at msdn for documentation about the following classes: DataSet, DataTable, OleDbDataReader, OleDbDataAdapter, DataRow, DataRelation and Constraint. After you read this material you will know the options that .net offer for data access and you will be able to choose the appropiate tools for your working scenarios.

Esteban Felipe
www.estebanf.com