I’m writing a program for Employees Management and i need to automatically generate a Payroll for each one then calculate some things and save it to another table.
I know how to calculate and save. I just need to get all the ID column of all rows in my Employees table, and select each Employee ID one by one in order to calculate each payroll automatically.
I’d appreciate your help.
If the information you need to look up based on the employeeID is in one other table, you may wish to use an Inner Join to select all the SQL data you need at once. Something like this:
In the select make sure you add the table name for any fields that are the same in both tables. Then you could make a list of items that hold all the data you collected, or calculate and store that information in whatever format you need it.
If you really only want the Ids from a single table that would look like this:
The code for generating the query and getting results will look something like this:
I used a list of Integer to hold the result since I am not sure what type your ID is.
If you have more than one field in the select you would add it to the loop, changing the type you are getting if necessary and then incrementing the index (reader.GetString(1) for example)
I am not sure which part of all this you weren’t sure how to proceed with… so I hope this went the right direction.