Multiuser problems!! need helps

Hi, everybody.

let we post the example to understand the problem:

I have 2 tables:

Person: (PersonID, PersonName, ...)

Phone: (PhoneID, PhoneNumber, PersonID) where PersonID is a foreign key.

based on the MSDN sample, I create a form to enter informations about persons with its phone numbers using the datagridview.

I have in my form:

textboxs to enter person informations and datagridview to enter the phones numbers.

PersonBindingSource

PersonBindingNavigator

PersonTableAdapter

PhoneTableAdapter

Phones_Persons_BindingSource (created Manually having PersonBindingSource as datasource, and FK_Phone_Person as datamember)

Normally I bind the navigator to PersonBindingSource, and the datagridview to Phones_Persons_BindingSource.

I got this method from creating Master_Detail form in MSDN.

this form works properly while one user use it. but when 2 user try to open this forms, no exceptions occured, but the phone number enterd by the second user will be joind to the phone number of the first user.

when the first user open the form and add new person:

automatically the Primary key PersonID will be 1 for example.

and if the second user open the form and add new person before that the first user save the new user, so the Primary key PersonID will be also = 1.

so any phone number entered in the datagridview will have 1 as personID (ForeignKey).

when saving, the user who precede will have the Primary key PersonID =1 and the other will be automatically changed to 2 . but the foreignkey PersonID will still=1. and so, the 2 number will be related to the first person that having the primary key = 1.

I hope that I explain the problem, but is there any way to catch the created primary key when saving (the real one) .

Thanks...




Answer this question

Multiuser problems!! need helps