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

  • Home
  • SEARCH
  • 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 6087977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:55:56+00:00 2026-05-23T11:55:56+00:00

This is what i am trying to do. I have a database that i

  • 0

This is what i am trying to do. I have a database that i am reading from using the code:

OleDbCommand command;
command = new OleDbCommand("SELECT " + Student.ID + " FROM " + newStudent.DataFile, conn);
conn.Open();
dt.Load(command.ExecuteReader());
conn.Close();

I then have the datatable bind to a datagridview and display the contents of the table.Now the problem is, i have more information to add to the datatable dt that is not in the database. For example, i have a field for the student object called Grade that is not found in the datafile but entered in by the user and stored in a property for the student object.

Instead of loading the query result into a datatable, is there a way to load it into a list so i can manually create rows and columns for a datatable in another method and then add the contents of the list(containing id) and the grade information in the student object manually?

  • 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-23T11:55:56+00:00Added an answer on May 23, 2026 at 11:55 am

    If you don’t fancy going for a full blown ORM framework such as the one @Bas has suggested…

    Take a look at the ToTable method available from on a Datatable’s Dataview. You can get the DataView for your Datatable simply using DataTable.DefaultView:

    List<Long> myList = dt.DefaultDataView.ToTable(True, "ID").AsEnumerable().ToList()
    myList.Add(1234)
    //etc
    

    Alternatively, you can load the additional data you want to append into a second datatable, and use the DataTable.Merge Method

    EDIT: To account for wanting to add additional columns, you can change the above list suggestion as follows:

    // Create a class to hold the information you want to bind, 
    // you could use anonymous types if preferred
    class MyDataRow
    {
        public long ID { get; set; }
        public string AnotherColumn { get; set; }
        public string AndAnotherColumn { get; set; }
    }
    
    // then later on when creating that list use something along the lines of:
    List<MyDataRow> myList = dt.DefaultDataView.ToTable(True, "ID").AsEnumerable().Select(x => new MyDataRow { ID = x.ID }).ToList()
    // you now have a list of MyDataRow which you can work with
    // for example...
    if (myList.Any())
        myList.First().AnotherColumn = "foo";
    
    // as an exmaple of using an anoymous type (not my preference, but an option nonetheless)
    var anonymousList = dt.DefaultDataView.ToTable(True, "ID").AsEnumerable().Select(x => new { ID = x.ID, whateverYouWantToCallIt = "some other data but this is read only property" }).ToList()
    // you can work with the anonymous list in much the same way, it just isn't explicitly declared
    // and the properties are Read Only
    if (anonymousList.Any())
        Console.WriteLine(anonymousList.First().whateverYouWantToCallIt);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have information displayed for this query: SELECT o.sub_number,o.unique_id,o.period_from,o.period_to,o.total_amt, i.paid_amt,i.dated,i.payment,i.paid_by,i.entered_date,i.paid_for_unique, j.cheque_num,j.drawn_on,j.dated
I am trying to have a tree display custom data that looks like this.
Is there anyone who knows this? I have been trying this for the last
I'm trying to have this block element to be horizontally aligned in the middle
I'm trying to have my Struts2 app redirect to a generated URL. In this
I'm trying this for almost two hours now, without any luck. I have a
This time I have an error which I have been trying again to figure
I have this output when trying to debug Program received signal SIGSEGV, Segmentation fault
I have been trying to get around this error for a day now and
I have been trying to tackle this problem , but I am having difficulty

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.