I am attempting to read values from an Excel sheet and dump them into a database. The Excel sheet is basically a time-card, which captures a daily time record count, along with time in and time out.
I am reading the values out of the sheet and adding them into a list of class that users helped me create on a previous post. I am performing this on a background worker. Adding users from the sheet to my list of class is fairly quick:
Now, the code attempts to write these items as inserts into my database:
The part of actually writing into the database on different computers can be fairly slow, depending on how many employees exist in the sheet. It has to do 7 inserts for each employee it finds. Is there a better way to approach the actual uploading to make this more efficient?
I am reading the values out of the sheet and adding them into a list of class that users helped me create on a previous post. I am performing this on a background worker. Adding users from the sheet to my list of class is fairly quick:
Code:
employee.WeekDays.Add(New TimeCapture(New Date(DateToUse.Year, DateToUse.Month, DateToUse.Day), timeIn, timeOutLunch, timeInLunch, timeOut, workHours, ptoHours, otHours, otherHours))
EmployeeListing.Add(employee)Code:
Dim employeeCount As Integer = (EmployeeListing.Count - 1) * 7
Dim tasksComplete As Integer = 1
For Each Employee In EmployeeListing
For Each WeekDayItem In Employee.WeekDays
bgwUploadTime.ReportProgress(0, "Uploading: " & Employee.EmployeeName & " - " & WeekDayItem.dtInput)
tblEntryAdapter.InsertNewTimeEntry(Employee.EmployeeID, Employee.EmployeeName, AreaUnit, WeekDayItem.dtInput, WeekDayItem.TimeIn, WeekDayItem.TimeOutLunch, WeekDayItem.TimeInLunch, WeekDayItem.TimeOut, WeekDayItem.HoursWorked, WeekDayItem.PTOHours, WeekDayItem.OvertimeHours, WeekDayItem.OtherHours, "Entered By: " & System.Security.Principal.WindowsIdentity.GetCurrent().Name)
tasksComplete += 1
bgwUploadTime.ReportProgress((tasksComplete / employeeCount) * 100)
Next WeekDayItem
Next Employee