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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:54:57+00:00 2026-05-23T09:54:57+00:00

I am quering a database and am wondering if there is a way to

  • 0

I am quering a database and am wondering if there is a way to load the results back into a list. The only way i curerntly know of how to get info from a database is within a datatable. I can always get it into a datatable and then loop through the rows in the datatable and add them to a list. But is there a way to directly get the result of a query into a list? This is my code:

OleDbCommand command= new OleDbCommand("SELECT ID, GRADE, PHONE from database WHERE PHONE=123456", conn);
conn.Open();
dt.Load(command.ExecuteReader());
conn.Close();

The result should be a list entry of the form (id, grade, phone):

61265,95,123456

Thanks

  • 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-23T09:54:57+00:00Added an answer on May 23, 2026 at 9:54 am

    Consider you have a class

    public ListData()
    {
      public int Id{get;set;} //Assuming DB field is int
      public string Grade{get;set;}  //Assuming DB field is a string
      public string PhoneNo{get;set;} //Assuming DB field is a string
    }
    

    Then you can do the following:

    list<ListData> theList =(from item in dt.AsEnumerable()
                             Select new ListData()
                                  {
                                     Id= (int)item["ID"],
                                     Grade = (string)item["GRADE"],
                                     PhoneNo = (string)item["PHONE"]
                                  }
                            ).ToList()
    

    Note:

    1. I just type it on the comment textbox so there might be some errors if you just copy-paste the code

    2. You also need to handle null values if any on GRADE / PHONE

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am querying a database for results and trying to convert them into JSON
I'm wondering if there's any relatively easy way to extend NHibernate to support F#'s
I was wondering if there is a simple way to store meta information about
I'm wondering what's the best way to do validation of database constraints (e.g. UNIQUE)
I am wondering the best way to insert a multidimensional array of values into
I know it's probably not the right way to structure a database but does
Jeff Atwood wrote once he found quering database for primary keys, and then getting
Question: I can get the SQL Server database language by querying: SELECT @@language And
My database is set up with a list of cases with an ID from
I would like to create buttons that change sorting of database output. Im quering

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.