Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Visual Basic .NET 2005/SQL Server 2005: simple relational linking btw two tables

Avatar of gwagnr
gwagnr asked on
Microsoft SQL ServerVisual Basic ClassicMicrosoft Development
11 Comments1 Solution355 ViewsLast Modified:
OK... I changed the requirements on the app I am working on to (hopefully) make it easier.  I know this shouldn't be difficult but I have been fighting this for over a week.

Platform: Visual Basic .NET 2005 Standard Edition, SQL Server 2005 Developer Edition

To simplify my actual issue, I have two tables:  Company and Employee.

Company
-----------
CompanyID
Name

Employee
-----------
EmployeeID
CompanyLink
EmployeeName

For each table, I have a form in VB using the binding control.  The ID fields are identity fields incrementing by 1.  All I want to do from the company form is press an employee button, see the employees currently linked to the selected company in the employee screen, and be able to add new employees to the employee screen, having them automatically link to the selected company.  This should be easy.  I am not sure what is the best way to do this as I run into the following issues:

1. I don't know what event in which to populate the CompanyLink field in.  Addnew seems too early, others don't account for the disconnected nature of the dataset and only update one record, etc.

2. Since the dataset is disconnected, multiple users will create an identity that is the same (ie: if the database has two records and two are adding at the same time, each person's next record will be ID #3)

I am lost on #1, on #2, I am thinking I need a stored procedure to get the next identity value and pass it into my form...  can anyone give me some advice or point me at some sample code?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of graye
grayeFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answers