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 8964341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:33:58+00:00 2026-06-15T16:33:58+00:00

I’m using VS2010 and C#. I have one DataTable which I want to convert

  • 0

I’m using VS2010 and C#. I have one DataTable which I want to convert to a List.

Suppose:
Table dt;

On run time want to create similar field from a datatable and fill fields in List.There is no existing class for list properties.

ListName=TableName
List property name=Table column name
List Property type=Table column type
List items=Table rows

Note: Recently work on EF.To fullfill my project requirement, need to give flexibility to use to input and execute ESQL at runtime .I don’t want to put this execute result on datatable or List<DataRow> ,want to put this result on list.
List has no existing class and property,don’t want to convert DataTable on list Type:DataRow

  • 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-06-15T16:33:59+00:00Added an answer on June 15, 2026 at 4:33 pm

    We are still not sure what are you trying to do, but if you want to create list of dynamic objects, you can try dynamic

    var dynamicList = new List<dynamic>();   
    

    Then you will have to assign values to that list through ExpandoObject

    And the you will have to Cast it to IDictionary to pass column names as properties.

    And then you can access list items like this item.YourColumnName

    Here’s a full example:

                var dynamicList = new List<dynamic>();
                DataTable dt = new DataTable();
                dt.Columns.Add("Col1");
                dt.Columns.Add("Col2");
                dt.Rows.Add("val1","val2");
                dt.Rows.Add("val3", "val4");
                foreach (DataRow dr in dt.Rows)
                {
                    dynamic myObj = new ExpandoObject();
                    var p = myObj as IDictionary<string, object>;
                    p[dr.Table.Columns[0].ColumnName] = dr[0];
                    p[dr.Table.Columns[1].ColumnName] = dr[1];
                    dynamicList.Add(p);
                }
    
                foreach (var item in dynamicList)
                {
                    Console.WriteLine(item.Col1 + " " + item.Col2);
                }   
    

    or linq also works of course for printing out the values:

    dynamicList.ForEach(x => Console.WriteLine(x.Col1 + " " + x.Col2));   
    

    this program will print out:

    val1 val2
    val3 val4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker

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.