accessing multiple databases and calculate interest in windows forms using sqlite

ROWLANDSFC 1 Reputation point
2021-03-14T17:12:21.253+00:00

i'm on a college course and part of it is studying programming, my current assignment is to create a basic application for a user to view customer, accounts, products and transfer databases. We are using windows forms app in visual studio and sqlite. i have it set up so you can view each table in a datagridview. i am able to update,add,delete each one. Part of the accounts table includes ISA balance and the daily accrued amount and the product able includes the interest rate for each product. What i need to do now is be able to update the accrued column for each account when the table is loaded. I have created method for calculating the number of days passed since the start of financial year and store it into a variable. I need now to go through the accounts table to get the balance and product type they have and the go through the product table to find the interest rate of each product and then calculate the accrued and update the accrued table with the new value.

    private void days()
    {
        year = DateTime.Now.Year - 1;
        DateTime start = new DateTime(year, 03, 13);
        DateTime end = DateTime.Today;

        TimeSpan span = end - start;

        difference = span.Days;
    }

I have a variable setup to store the product i and a method ready to run make the calulations based on what the product id is.

if(Global.productID == "1")
        {
            interestRate = 0.03/365;
            Global.accrued = (interestRate * double.Parse(Global.balance))* difference;

        }
        if (Global.productID == "2")
        {
            interestRate = 0.07/365;
            Global.accrued = (interestRate * double.Parse(Global.balance)) * difference;
        }

I'm at a loss as to where to go from here so any help or guidance would be appreciated

foreach (DataRow row in dt_Accounts.Rows)
            {
                Global.productID = row["prodid"].ToString();
                Global.balance = row["balance"].ToString();
                interest();
                row["accrued"] = Global.accrued.ToString();

            }

i have tried the code above but that didnt work

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,831 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,743 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,267 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,611 Reputation points
    2021-03-15T06:52:35.603+00:00

    Hi rowlandsfca,
    >>What i need to do now is be able to update the accrued column for each account when the table is loaded
    I suggest you can update the accrued column in DataGridView.DataBindingComplete event which occurs after a data-binding operation has finished.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments