C#.Net + populate object

Posted on 2010-01-03
Last Modified: 2013-11-08
i am trying to learn about objects, can i populate an object with an array of values, something simple like and list of ids and corrosponding names, i would like to get the list of names and id from a db and populate the object.
Question by:dkilby
    LVL 42

    Accepted Solution

    yes u can, u need to declare your object to reflect the data u wish to populate from the database.
    then u can use different methods to populate the object with the query result.
    your question is quite generic, if u wish to get into details i'd suggest u post more practical requirements such as object structure, db type, query output etc.
    LVL 11

    Expert Comment

    Why not, just write a simple method to populate the object.
    But why you have to do so?
    LVL 10

    Assisted Solution

    In this case, I would suggest you create a class with 2 properties: "Id" and "Name".
    For every row in your results from your database-query, you create a new instance of that class (= an object) and fill in the properties.

    You can add all those objects to a generic List object, to make it easy to work with as a collection.

    Hope this helps.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now