INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

HOW TO DELETE TWO LINKED ROW FROM MYSQL DATABASE USING DELPHI ???

HOW TO DELETE TWO LINKED ROW FROM MYSQL DATABASE USING DELPHI ???

HOW TO DELETE TWO LINKED ROW FROM MYSQL DATABASE USING DELPHI ???

(OP)
Hello,

Can somebody show my how to delete two linked row using delphi.

I Use delphi 2007 and MySql.

In MySql i have database with two Table. Table Contacts(ID, FirstName, LastName, Phone, PICID) and table Picture(ID, IMG)
MySql Tables:

CODE -->

CREATE TABLE `Picture`.`Picture` (
  `ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `IMG` LONGBLOB,
  PRIMARY KEY (`ID`)
)
ENGINE = InnoDB; 

CODE -->

CREATE TABLE `contacts` (
  `ID` int(10) unsigned NOT NULL auto_increment,
  `FirstName` varchar(45) NOT NULL,
  `LastName` varchar(45) NOT NULL,
  `Phone` varchar(45) default NULL,
  `PICID` int(10) unsigned default NULL,
  PRIMARY KEY  (`ID`),
  KEY `FK_contacts_1` (`PICID`),
  CONSTRAINT `FK_contacts_1` FOREIGN KEY (`PICID`) REFERENCES `picture` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1; 

In my Delphi Application I have Delete Button. When I find some Contact on my DBGrid and press DELETE Button I can delete only contact from table Contact, I aslo want to delete contact picture.

I want to delete row from table CONTACTS and row from Table PICTURE. Table Picture Is linked to table Contact With foreign key.

RE: HOW TO DELETE TWO LINKED ROW FROM MYSQL DATABASE USING DELPHI ???

Hi,

I have no experience with MySQL, but I think you could activate the action Cascade in the foreign key to automatically delete the Picture when delete a Contact.

If you really want to delete by the application, then you can use code in BeforeDelete event of Contacts DataSet to delete the picture.

Hope this helps.

http://www.imoveisemexposicao.com.br/imoveis-venda-são_paulo-residencial-apartamento

RE: HOW TO DELETE TWO LINKED ROW FROM MYSQL DATABASE USING DELPHI ???

(OP)
Thank you imex.

It is working! :)

RE: HOW TO DELETE TWO LINKED ROW FROM MYSQL DATABASE USING DELPHI ???

(OP)
Hello imex,

I have small problem with deleting row from two table. Can you help me with this.

I put code in BeforeDelete event of Contacts DataSet to delete the picture how you tell me.
I can delete Row but I always delete the last insert row.

if I want to delete contact with ID=7(from table Contacts) I will delete Contact Picture with ID=15 (from table Picture).

ADODataSet for table Contact is my "TContacts"
ADODataSet for Table Picture is my "TPicture"
Data modul is my "dm"

For delete contacts I use this code: dm.TContacts.Delete; - works fine
For BeforeDelete event of Contacts DataSet(TContacts) to delete the picture I use this code: dm.TPicture.Delete - But I delete only last inserted row.
Table Contacts and table Picture are conected with FOREIGN KEY. table CONTACTS(PICID)-->(ID) table PICTURE.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close