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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:06:00+00:00 2026-06-16T10:06:00+00:00

I am doing a program where i have used a class with 4-5 attributes

  • 0

I am doing a program where i have used a class with 4-5 attributes

public class Car
{
    public string Make;
    public string Model;
    public int Year;
    public int Doors;
    public string Colour;
    public float Price;
}

now from sql query I want o fill the value of List and return same like this..

List<Car> lrs = null;


while (rdr.Read())
                        {
                            lrs = new List<LocationResult>{ new LocationResult{Make=(string)rdr["Make"], Model=null, Year=null, Doors=null, Colour=null, Price=null}};
                        }

Everything is working fine with code except, that lrs only contains the last row of sql after above run completes. It get overwritten with while loop each time. So how am i supposed to keep adding new rows ..

if i do..

lrs.add("") - it only accepts one parameter ....

Any help with be appreciated…

  • 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-16T10:06:01+00:00Added an answer on June 16, 2026 at 10:06 am
    List<Car> lrs = new List<Car>();
    
    while (rdr.Read()) {
    
      Car c = new Car();
      c.Model = rdr. ... /* get model from reader...*/;
      c.Make = rdr. ... /* get make from reader...*/;
      /* ... */
    
      lrs.add(c);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program for the iPhone that is supposed to be doing intelligent
I am basically doing a tutorial but my program seems to have errors that
i, I have to run about a 100 tests on my program and doing
I have a program in python that includes a class that takes a function
So in my class declared as public class pcb , I have the following
I have a WPF/C# program with several classes, and the MainWindow.cs class has user
Coming from a c++/make background, I'm used to doing something like this to build
Code first questions later... public class Program2 { //The custom word object used when
I have an abstract class Person and and interface comparable, which is also used
in my C#-Silverlight-3-Application, I have created a class, that is doing some calculations that

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.