If not which structure should I use ?
You can add a new DataTable
to a DataTable
cell.
Simple Example:
Define the primary table with one cell type DataTable
:
DataTable people = new DataTable();
people.Columns.Add("Name", typeof(string));
people.Columns.Add("Friends", typeof(DataTable));
Define the sub table:
DataTable friends = new DataTable();
friends.Columns.Add("Name", typeof(string));
friends.Columns.Add("Desire", typeof(string));
Add some data to the sub table:
friends.Rows.Add("Scarecrow", "brain");
friends.Rows.Add("Tin Woodman", "heart");
friends.Rows.Add("Cowardly Lion", "courage");
And finally, add a row to the primary table:
people.Rows.Add("Dorothy", friends);
To get the sub table from the primary table you need to cast the object as DataTable
:
DataTable output = (DataTable)people.Rows[0]["Friends"];
DataSet can contain several datatables with different schemas. You can store your second datatable in a second table and reference it to your row at first table.
Also you can use WriteXml and ReadXml methods to store your datatable into a data cell.
1: Take a look at that answer. 1: What are useful JavaScript methods that extends built-in objects?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With