TableAdapter.Update( [DataRow] ) returns 1 but does not update DB!

nelmr

New member
Joined
Jul 6, 2009
Messages
1
Programming Experience
5-10
Here is my code to update the table:

Dim dTable As New PersonDataTable
Dim dRow As PersonRow = dTable.NewPersonRow
... (setting the properties of the row)
Dim rowsAffected As Integer = PersonTableAdapter.Update(dRow)

rowsAffected = 1 after this command. Then I go and write another record to the database

Dim dTable As New ResidenceDataTable
Dim dRow As ResidenceRow= dTable.NewResidenceRow
...
dRow.PersonID = (value of forign key to the table just created above)
...
Dim rowsAffected As Integer = ResidenceTableAdapter.Update(dRow)

When I try to create this table I get an error:

A foreign key value cannot be inserted because a corresponding primary key value does not exist. [ Foreign key constraint name = Person To Residence ]

The person table contains no foreign keys and is thus why I write to it first. Also, when I go to the debug folder and look at the sdf file nothing was written to the persons table. I've tried my sdf file as Copy if newer or Do Not Copy. It doesn't matter. The sdf file does not get updated even when I stop the code after the TableAdaper.Update command after it returns one. What the am I doing wrong?
 
Back
Top