Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert a datatable to a related dataset

I have denormalized data in a DataTable.

The data contains employee names, and the pay they got over a series of pay cycles. i.e.:

My DataTable contains:

Employee 1    Jan-1-2012     $100
Employee 2    Jan-1-2012     $300
Employee 1    Feb-1-2012     $400
Employee 2    Feb-1-2012     $200
Employee 1    Mar-1-2012     $150
Employee 2    Mar-1-2012     $325

How can load this data into a DataSet where the parent DataTable contains the employees name, and the child DataTable contains details of the paycheck?

like image 656
MillinMo Avatar asked Jul 29 '12 16:07

MillinMo


People also ask

What is difference between DataTable and DataSet?

DataSet comprises one or many dataset tables which have the in-memory feature. DataTable holds a single or unit database table that has an in-memory feature. DataSet is formed collectively of datatables. DataTable is composed of multiple rows and columns to have better access to data.

How can we add relation between tables in a DataSet?

Just right-click on the table in the designer, select Add->Relation, and specify the relation. If you need to specify the relation in code, you can do it like this: dataSet. Relations.

What is the difference between DataView DataTable and DataSet?

DataTable means single table representation whereas a DataSet is a multiple table representation. That means by using DataTable we can hold only one single table from the database, if we use DataSet we can hold multiple tables at a time... DataView means view of data available in DataSet ...


1 Answers

DataSet is nothing but a collection of DataTables. So to "load" the dataTable into dataSet simple Add it:

        DataTable employees = new DataTable();
        DataTable payCheckes = new DataTable();
        DataSet ds = new DataSet();
        ds.Tables.Add(employees);
        ds.Tables.Add(payCheckes);

Do you want to "combine" datatables somehow? Get paycheckes of each employee?

like image 54
Mitja Bonca Avatar answered Oct 15 '22 03:10

Mitja Bonca