Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 507999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:51:43+00:00 2026-05-13T06:51:43+00:00

I am trying to achieve nesting in DataTable, i.e. a column of DataTable is

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:51:44+00:00Added an answer on May 13, 2026 at 6:51 am

    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:

    TableOne:
        int          PrimaryKey
        nvarchar(50) Name
    
    TableMany:
        int          ForeignKey
        nvarchar(50) Qualification
        int          Grade
    
    TableOne sample content:
        PrimaryKey     Name
        1              Alice
        2              Bob
        3              Charlie
    
    TableMany sample content:
        ForeignKey     Qualification    Grade
        1              Driving          100
        1              Acting           60
        1              Singing          30
        2              Driving          40
        2              Piloting         90
        2              Snowboarding     80
        3              Dancing          70
        3              Tennis           30
    

    Example Code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    
    namespace datatests
    {
        class Program
        {
            static void Main(string[] args)
            {
                Program p = new Program();
                p.Main();
            }
    
            DataSet dataSet;
            DataTable TableOne, TableMany;
            DataRelation OneToManyRelation;
    
            void Main()
            {
                dataSet = new DataSet();
    
                TableOne = new DataTable();
                var TableOnePK = TableOne.Columns.Add("PrimaryKey", typeof(int));
                TableOne.Columns.Add("Name", typeof(string));
    
                TableMany = new DataTable();
                var TableManyFK = TableMany.Columns.Add("ForeignKey", typeof(int));
                TableMany.Columns.Add("Qualification", typeof(string));
                TableMany.Columns.Add("Grade", typeof(int));
    
                dataSet.Tables.Add(TableOne);
                dataSet.Tables.Add(TableMany);
    
                TableOne.Constraints.Add("PK", TableOnePK, true);
                OneToManyRelation = new DataRelation("OneToMany", TableOnePK, TableManyFK);
    
                TableOne.ChildRelations.Add(OneToManyRelation);
    
                // Populate TableOne with sample data.
                AddTableOneRow(1, "Alice");
                AddTableOneRow(2, "Bob");
                AddTableOneRow(3, "Charlie");
    
                // Populate TableMany with sample data.
                AddTableManyRow(1, "Driving", 100);
                AddTableManyRow(1, "Acting", 60);
                AddTableManyRow(1, "Singing", 30);
                AddTableManyRow(2, "Driving", 40);
                AddTableManyRow(2, "Piloting", 90);
                AddTableManyRow(2, "Snowboarding", 80);
                AddTableManyRow(3, "Dancing", 70);
                AddTableManyRow(3, "Tennis", 30);
    
                var parentRow=TableOne.Rows[0];
                var childRows = parentRow.GetChildRows(OneToManyRelation);
                Console.WriteLine("Data for record key #{0}, Name={1}", 
                    parentRow["PrimaryKey"], 
                    parentRow["Name"]);
                Console.WriteLine("Qualifications:");
                foreach (DataRow childRow in childRows)
                {
                    Console.WriteLine("    {0}: {1}", 
                        childRow["Qualification"], 
                        childRow["Grade"]);
                }
            }
    
            private void AddTableManyRow(int fk, string qual, int grade)
            {
                var newRow = TableMany.NewRow();
                newRow["ForeignKey"] = fk;
                newRow["Qualification"] = qual;
                newRow["Grade"] = grade;
                TableMany.Rows.Add(newRow);
            }
    
            private void AddTableOneRow(int key, string name)
            {
                var newRow = TableOne.NewRow();
                newRow["PrimaryKey"] = key;
                newRow["Name"] = name;
                TableOne.Rows.Add(newRow);
            }
        }
    }
    

    Sample output:

    Data for record key #1, Name=Alice
    Qualifications:
        Driving: 100
        Acting: 60
        Singing: 30
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've trying to achieve something like this: class Base { public: Base(string S) {
I'm trying to achieve something google isn't able to give answer. I'm trying to
I am trying to achieve better performance for my Java SWT application, and I
What I am trying to achieve is a form that has a button on
What I'm trying to achieve is to determine if the Postscript that I'm parsing
I'm trying to achieve the equivalent of a WinForms ListView with its View property
I'm trying to achieve a 50px space at the bottom of my page, below
I am trying to achieve the same behavior as indicated in the following post.
What I am trying to achieve is to merge three strings. Two are provided
What i am really trying to achieve is to full control the active TabItem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.