Re: Removing rows from two connected tables
- From: Pavel Minaev <int19h@xxxxxxxxx>
- Date: Fri, 13 Mar 2009 22:04:06 -0700 (PDT)
On Mar 13, 9:12 pm, "mick" <coughco...@xxxxxxxxxxx> wrote:
I have two tables Game and Disks
Game-
GameID (PrimaryKey)
GameName
...
Disks
DiskID
...
GameID (ForeignKey)
On my Form I have a listbox that shows the GameName field for each row.
When the Remove_button is pressed the selected listbox item is removed
from both the Game and Disk tables. The problem was, however when I
hit the
gameTableAdapter.Update(gamesArchiveDataSet);
I got the following error-
The DELETE statement conflicted with the REFERENCE constraint
"FK_Disks_Game". The conflict occurred in database
"C:\USERS\MICK\DOCUMENTS\VISUAL STUDIO 2008\PROJECTS\GAME ARCHIVES\GAME
ARCHIVES\BIN\DEBUG\GAMESARCHIVE.MDF", table "dbo.Disks", column 'GameID'.
The thing is, when I commented out this line and just did the Update() on
the "Disk" table it worked and the rows
from _both_ of the tables were removed from the Dbase. I`m pleased that it
works but I was wondering if
someone could give a little explanation why it works and why the updating of
the gameTableAdapter fails.
Most likely, when you do the Update() on games, it tries to delete
record from Games table first, and only then those from Disks. If you
have any records in Disks referencing the one you're trying to delete
from Games, then deletion would result in a foreign key constraint
violation (since you would get a bunch of Disks that reference a non-
existing Game).
.
- Follow-Ups:
- Re: Removing rows from two connected tables
- From: mick
- Re: Removing rows from two connected tables
- References:
- Removing rows from two connected tables
- From: mick
- Removing rows from two connected tables
- Prev by Date: Re: DataSet.DataMember – it doesn’t work as expected
- Next by Date: Re: Binary Serialization of a class with a field that has been Xml Serialized
- Previous by thread: Removing rows from two connected tables
- Next by thread: Re: Removing rows from two connected tables
- Index(es):
Relevant Pages
|