I am using Visual Studio and VB.NET to create an application that connects to an MS Access database. I have a function that inserts a new employee. In the Load Event of my form I fill my employees table in my dataset. There is a button on the formt that is clicked to do the insert.
I have included the insert code under CLICK EVENT. Basically, I add a new row to my employees table, use a datarow to set the values, call the Add method of my emjployee table to add the new row and then call the Update method of the employee tableadapter to update the database.
Everything works as expected except one thing. The EmployeeRow has a unique id, EmployeeID, that is an autoincrement field. After the insert, the number of employees in both the employee table and employee table adapter increment by 1. However, in the employee table, the EmployeeID is -1 while in the database the EmployeeID of the new record is 10108. How can I get my dataset to reflect the correct EmployeeID? Do I need to unload the table and reload it or is there an easier way?
EmployeeRow = PfmsDataSet1.Employees.NewRow()
EmployeeRow.EmployerID = 5 ' Set to Fair Share
EmployeeRow.SocialSecurityNumber = ec.SSN
EmployeeRow.FirstName = ec.FirstName
EmployeeRow.LastName = ec.LastName
EmployeeRow.HireDate = ec.DOH
EmployeeRow.ActiveDateinPlan = ec.DOH
EmployeeRow.EmployeeStatus = ec.EmployeeStat
EmployeeRow.PlanStatus = ec.PlanStat
EmployeeRow.EmployeeType = ec.EmployeeType
EmployeeRow.State = "PA"
EmployeeRow.Sex = "UNKNOWN"
EmployeeRow.MaritalStatus = "UNKNOWN"