Groups > Databases > Access Databases and AccessDataSource Control > Re: Deleting from details view coming from access data source




Deleting from details view coming from access data source

Deleting from details view coming from access data source
Tue, 18 Mar 2008 14:00:09 +000
Hows it going, I have a grid view that has a horse id and name on it, when one
is selected a details view comes up with all the rest of the information on
them. I can add to it no problem using:

INSERT INTO Horse(Name, Age, Sire, Dam, SireDam, Points, RiderID, OwnerID)
VALUES (@Name, @Age, @Sire, @Dam, @SireDam, @Points, @RiderID, @OwnerID)

When I update i get no error message but no update either.

UPDATE Horse SET Name=@Name, Age=@Age, Sire=@Sire, Dam=@Dam,  SireDam=@SireDam, 
Points=@Points, RiderID=@RiderID, OwnerID=@OwnerID WHERE HorseID=@HorseID

When I delete there is a problem as the Horse table is joined to another in MS
Access using a one to many relationship with horseID being the primary key, 


DELETE FROM Horse WHERE HorseID=HorseID 


The error message is The record can not be deleted or changed because table
'Entry' includes related records.

Any help on this would be great

Thanks
Post Reply
Re: Deleting from details view coming from access data source
Tue, 18 Mar 2008 15:30:52 +000
For the Update, make sure that the parameters are added to the command in the
order in which they appear in the SQL.  With the Delete, in the Deleting event
of the DataSoruce control, run a command that deletes from the related table
first.
Post Reply
Re: Deleting from details view coming from access data source
Tue, 18 Mar 2008 15:41:27 +000
Thanks for the reply Mike, iv been looking at the update for ages and i cant see
anything that does not match up, probably something small somewhere. On the
delete one what sort of command would be used?

Delete from Enrty where HorseID=HorseID

and 

DELETE FROM Horse WHERE HorseID=HorseID  

Would that be the sort of thing or is there a specific word for it

Cheers
Post Reply
Re: Deleting from details view coming from access data source
Tue, 18 Mar 2008 19:29:59 +000
The Sql you need to run in the Deleting event is Delete From Entry Where
HorseID=@HorseID.  The DeleteCommand stays the same, but will run after the
Deleting Event, by which time the related entry win Entry will already have been
removed.

With regard to the update, you probably need to post the code for the
AccessDataSource control.
Post Reply
Re: Deleting from details view coming from access data source
Tue, 18 Mar 2008 20:01:38 +000
I sorted the update out thanks, basic stupidity on my behalf but delete is a
different story, the code i went for was

DELETE FROM Entry WHERE HorseID=@HorseID 

DELETE FROM Horse WHERE HorseID=@HorseID 


The error message im getting is syntax error (missing operator) in query
expression 'HorseID=@HorseID DELETE FROM Horse WHERE HorseID=@HorseID'

Sorry for being a pain but does that help or am i gone totally wrong?
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact