How do I get the unique id from my table when a new row is added to my dataset

Posted on 2008-11-19
Last Modified: 2013-11-26
Please bear with me as I am new to Visual Basic.  I'm using Visual Studio to develop a Windows application.  The database I am connecting to is MS Access.  I can successfully add new records to the database.  What I now need to do is each time I add a new employee to the database, I want to retrieve the unique id (ID autonumber) from the just added record so I can use it to add a "History" record to another table that maps back to the new employee.  I will be adding a lot of employees so I want to wait until all of the employees have been added to the dataset before I update the physical database using the following code:  Me.EmployeeTableAdapter.Update(Me.HWDataSet.Employee).

What I need is the code that will retrieve the unique id generated from the Me.HWDataSet.Employee.Rows.Add(EmployeeRow) call.

Any help would be greatly appreciated!
Dim EmployeeRow As HWDataSet.EmployeeRow

' Insert Employee into dataset



Catch ex As Exception


End Try

Open in new window

Question by:dyarosh
    LVL 15

    Accepted Solution

    Follow the link from Microsoft.. :)

    Author Comment

    Thanks for the link.  The article runs the Identity Select after an Update() is called.  I was hoping to hold off on calling Update() until after all of the records have been loaded into the dataset.  Is there a way to do this?

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now