Share via

Question about Datatable

c00012 741 Reputation points
Mar 28, 2022, 12:25 PM

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

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,788 questions
{count} votes

Your answer

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