這是兩個方法時遇到的從一個數據庫表讀數,並將其存入兩個對象
一個問題,我想回到csVehicle和csDistributor 的兩個對象,你我的代碼下面只返回csVehicle
請幫助
public List<csVehicle> get_All_Vehicles()
{
var objv = new List<csVehicle>();
IDataReader dr = null;
var objdal = new csDAL();
dr = objdal.executespreturndr("sp_Get_All_Distributor");
while (dr.Read())
{
var d = new csDistributor(); // I put this here so that I can use the propDistrbutorId
var v = new csVehicle();
populate_Data(dr, d,v);
objv.Add(v); //It only adds object of csVehicles and csDistributor is not added
}
return objv; // csDistributor is not returned
}
的populate_Date方法將數據添加到兩個對象csDistributor和csVehicle
private void populate_Data(IDataReader dr, csDistributor d, csVehicle v)
{
v._vehicleRegNo = dr["VehicleRegNo"].ToString();
d.propDistrbutorId = Convert.ToInt32(dr["DistrbutorId"]);
}
嘗試puting一個破發點中populate_data方法,看看醫生的工作的價值[「DistributorId」]是。 – Kell
您正在創建一個只有csVehicle而不是csDistributor的集合(示例列表())。您在csVehicle類中擁有哪些屬性? –
praveen