Question calculating interest amount based on values from datagridview

rowlandsfc

Active member
Joined
Feb 3, 2019
Messages
43
Location
bridgend
Programming Experience
Beginner
hi i have an application that displays customers accounts in one table and products information which includes the interest rate for that specific product in another table, both tables get displayed inside a datagridview. for my accounts database there is an accrued column which i need to code so that it updates each day. i have it set up so that total days between start of the financial year and now is calculated and stored in a variable called days., im not really sure where to start when it comes to going through the datagridview to do all the calculations to for accrued then add it back into the database. i have a method set up to check a variable for a productid to find out what interest rate to use when doing the calculations. my first thought was to run through the datagridview row by row and take out the productid then run the method and dothe calculationsfor accrued and then update the datbase before moving onto the next row. but when i run the code i get 'Object reference not set to an instance of an object.'

foreach loop:
foreach (DataGridViewRow accrued in dgv_Account.Rows)
            {
               Global.productID = accrued.Cells[2].Value.ToString();
      
            }

im stuck as to where to go from here, any help would be appreciated thanks
 
Personally, I would talk to my DBA about how to schedule a daily scheduled stored procedure which would update the data. Something is really wrong if the data update is dependent on someone running code on some arbitrary client side machine. What of someone messes with the system clock on that client machine in an attempt to bypass an expiring software license? Does that mean the customers suddenly get lower or no interest charges? What if that person loses power or network connectivity for a week? A week flat interest cost and then a sudden jump when the client machine can finally log back in again re-run the interest update?
 
It is rather crazy using a manually executed WinForms application for this. As suggested, it ought to be done in the database if possible. You could schedule a stored procedure in SQL Server or perhaps use an SSIS package if you need something more complex. Failing that, using Windows Scheduled Tasks to run a Console app would be the next best option. Manually running a WinForms app should be the absolute last thing you use.

If you really were to use a WinForms app, e.g. this was actually homework and not a proper app, then the DataGridView should be irrelevant. You might use one to view the data before and after processing but the code shouldn't care about it. You would use ADO.NET to pull that data back into a DataTable and bind that to the grid if desired. All your code should operate on that DataTable though.

As with any other programming problem, you should forget that it's a programming problem. Assume that you have a table of data printed out on a page. If you had pen, paper and a calculator to perform the task manually, what would you do? Think about that and work out the logic, then formalise that logic into an algorithm. Test the algorithm manually on a number of data sets to make sure that it works. Only once you've confirmed the algorithm should you consider writing code and that code should be to explicitly implement your algorithm. That way, if the code doesn't work you can compare it to the algorithm and see exactly where and how it doesn't work and fix it. If it implements the algorithm faithfully but still doesn't produce the expected result then your algorithm is wrong, so you go back to the drawing board and fix the algorithm. If you don't know what your code is supposed to do, you shouldn't be writing code. That doesn't mean just the result but rather the steps to get to the result.
 
Personally, I would talk to my DBA about how to schedule a daily scheduled stored procedure which would update the data. Something is really wrong if the data update is dependent on someone running code on some arbitrary client side machine. What of someone messes with the system clock on that client machine in an attempt to bypass an expiring software license? Does that mean the customers suddenly get lower or no interest charges? What if that person loses power or network connectivity for a week? A week flat interest cost and then a sudden jump when the client machine can finally log back in again re-run the interest up
ok its for a college course so they havent gone over anything like that and we are using sqlite is this doable using sqlite? but i will take a look into it and see if i can get it working, thanks
 

Latest posts

Back
Top Bottom