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...