Question about Datatable

c00012 746 Reputation points
2022-03-28T12:25:18.277+00:00

Hello,

I want to show payment schedule on datatable like this;
187497-ice-screenshot-20220327-225113.png

so I wrote a code for handling data like this;

            for (int i = 0; i < Convert.ToInt32(Terms) * 12; i++)  
            {  
                DataRow dataRow = amortable.NewRow();  
                dataRow["Terms"] = i + 1;  
                if(i==Convert.ToInt32(Terms)*12-1)  
                    dataRow["Payment"] = Math.Round(Convert.ToDouble(Payment)+Convert.ToDouble(Residualvalue), 4);    
                dataRow["Payment"] = Math.Round(Convert.ToDouble(Payment), 4);   
                dataRow["Interest"] = Math.Round(APR / 12  * Convert.ToDouble(amortable.Rows[i].Field<double>("Balance")), 4);  
                dataRow["Principal"] = Math.Round(Convert.ToDouble(dataRow["Payment"]) - Convert.ToDouble(dataRow["Interest"]), 4);  
                dataRow["Balance"] = Math.Round(Convert.ToDouble(amortable.Rows[i].Field<double>("Balance")) - Convert.ToDouble(dataRow["Principal"]), 4);  
                if (Convert.ToDouble(dataRow["Balance"]) < 0.0)  
                    dataRow["Balance"] = 0.0;  
                amortable.Rows.Add(dataRow);  
            }  

However, When I run the code I realized this code didn't work.

Full source code: https://github.com/c00012/WpfApp2

please give me an advice to fix an error.

thanks,

c00012

Developer technologies | Windows Presentation Foundation
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.