I am trying to achieve nesting in DataTable, i.e. a column of DataTable is a DataTable. My code is something like this:
DataTable table = new DataTable();
DataColumn column = new DataColumn(“Qualifications”, System.Type.GetType(“System.Data.DataTable”));
table.Columns.Add(column);
I am getting a runtime error message at line # 2, that says “Column requires a valid DataType”. What could be the reason?
I would say that what you are attempting to achieve is not possible using the way you specified. To achieve a relationship between an entity and several sub-entities use a one-to-many relationship between one table and another table.
This means you have two separate tables, call them for instance TableOne and TableMany. In TableOne put all the fields that describe your entity, and make sure to have a primary key. In TableMany put all the fields that describe your sub-entities, and include a field which is of the type of the TableOne primary key field, which relates each sub-entity to its owning entity.
For examle:
Example Code:
Sample output: