Ho Can i Add data to list in inside list using model in c#,
I have referred code form below url but they are directly entering value, i need to loop through each row?
C# - Adding data to list inside list
below is my code
public class AllClaimDetails
{
public class AllClaims
{
public string VendID { get; set; }
public int VendKey { get; set; }
public string CompanyID { get; set; }
public IList<ClaimLots> Lots { get; set; }
}
public class ClaimLots
{
public string LotNo { get; set; }
public string InvoiceType { get; set; }
public string TranNo { get; set; }
public int TranType { get; set; }
public decimal TranAmount { get; set; }
public decimal ApplyAmount { get; set; }
public int Status { get; set; }
}
}
DataTable dt = new DataTable();
SqlDataReader rdr = cmd.ExecuteReader();
dt.Load(rdr);
List<AllClaims> requestObject = new List<AllClaims>();
for (int i = 0; i < dt.Rows.Count; i++)
{
AllClaims claims = new AllClaims()
{
VendID = dt.Rows[i]["VendID"].ToString(),
Lots = new List<ClaimLots>()
{
new ClaimLots{
LotNo=dt.Rows[i]["LotNo"].ToString(),
TranNo=dt.Rows[i]["TranNo"].ToString(),
TranType=Convert.ToInt32(dt.Rows[i]["TranType"].ToString()),
//TranAmount=Convert.ToInt32(dt.Rows[i]["TranAmt"].ToString()),
Status=Convert.ToInt32(dt.Rows[i]["Status"].ToString())
}
}
};
requestObject.Add(claims);
}