I am currently trying to use an SQLite database with a DataGridView in C#.
I have seen an example program which does the following:
DataSet combinedDataSet = new DataSet();
DataTable ContactsTable = CombinedDataSet.Tables.Add("contacts");
DataTable FoodTable = CombinedDataSet.Tables.Add("food");
SQLiteDataAdapter ad = new SQLiteDataAdapter(command)
ad.Fill(FoodTable);
ad.Fill(ContactsTable);
This data table is then used as the source for a datagridview.
My Question is this:
Why use a DataSet? Why not just go straight to a DataTable?
I am sure there is a very good reason, but having taken it out of the code, it still appears to run fine.
A DataSet is an in-memory representation of relational data. In particular, it may contain several DataTables, with relations between them.
See “DataSets, DataTables, and DataViews (ADO.NET)” for a good set of overview articles. You’ll see how the DataSet maintains a collection of DataRelation objects, and how each DataTable maintains it’s own collection of parent and child relations.