I have a csv file contains following data: ProdCode, Lender, LoanAmt, APR, Terms, Payment.
I want to store these data into datatable so I defined it like this;
- define column:
DataTable dt = new();
dt.Columns.Add("Term", typeof(int));
dt.Columns.Add("Payment", typeof(double));
dt.Columns.Add("Principal", typeof(double));
dt.Columns.Add("Interest", typeof(double));
dt.Columns.Add("Balance", typeof(double));
- add row:
for (int i = 0; i < Convert.ToInt32(off.Terms) * 12; i++)
{
DataRow row = dt.NewRow();
if (i==0)
{
row["Balance"] = Convert.ToDouble(off.LoanAmt);
}
row["Term"] = i + 1;
row["Payment"] = Convert.ToDouble(off.Payment);
row["Interest"] = Convert.ToDouble(off.APR) / 12 * Convert.ToDouble(row["Balance"]);
row["Principal"] = Convert.ToDouble(row["Payment"]) - Convert.ToDouble(row["Interest"]);
row["Balance"] = Convert.ToDouble(row["Balance"]) - Convert.ToDouble(row["Principal"]);
if(Convert.ToDouble(row["Balance"])<0.0)
{
row["Balance"] = 0.0;
}
dt.Rows.Add(row);
}
after running above code, I got an error message:
If somebody pick my fault, I would be very appreciated.
thanks,
c0012