Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2007, 08:09 AM
Authorized User
 
Join Date: Jun 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Similar Delete Cascade

Hi All,

I am able to delete mapping table values in different tables using "delete cascade" ie I can delete using back end Database directly. I want to know the same can be implemented from code behind using C#. What will be the syntax to be followed and constraints to consider.




Thanks

Prasanna
__________________
Thanks

Prasanna
 
Old August 26th, 2007, 01:44 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Huh? Cascade operations are for relational databases. How are you expecting to do this in code? What in code are you deleting that you want to cascade to?

-Peter
 
Old August 26th, 2007, 11:26 PM
Authorized User
 
Join Date: Jun 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Peter,

Thanks for the reply,
I want to write a code which deletes a row, while deleting this row it needs to consider if any foreign key associated with this row. If yes then it need to delete that value before deleting present row. I have done this using SQL and presently trying if this is possible from C#, as this gives me full control of database.
Hope am clear with my question.


Thanks

Prasanna
 
Old August 27th, 2007, 08:13 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Is there a reason you can not use the built in cascade delete functionality of the database engine?

Are the foreign keys known or unknown? Would you want the relationships to be discovered by the code? That would be a rather complex task as you would have to query schema tables to discover what other tables relate to the one you are initially deleting from.

-Peter
 
Old August 28th, 2007, 12:49 AM
Authorized User
 
Join Date: Jun 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Peter,

You are Right, can you please give a small example of how to get the relations using C#. Using code, we should be able to check foreign key and then delete..




Thanks

Prasanna
 
Old August 28th, 2007, 03:20 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Prasanna,

If you look at Peter's post, you will see:
Quote:
quote:That would be a rather complex task
So I think asking for code may be a little.. inappropriate.
I think it would be a bad idea to do all this in code.. This sort of thing should definately be put on to the server. By definition, the Database Management System should be managing the data, both access and integrity.

If you have already done this in SQL, why bother moving it to the code?

Regards,

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
 
Old August 28th, 2007, 04:12 AM
Authorized User
 
Join Date: Jun 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Peter and Rob for your valuable inputs,
I was assuming that my client should have full control the database.
Views appreciated

Thanks

Prasanna





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2005 Delete on cascade DarkForce SQL Language 0 October 11th, 2008 08:24 AM
How can i add constraint on update cascade without mahen_pali SQL Server 2005 1 May 3rd, 2008 03:28 PM
How apply cascade update/delete in sql server ? method SQL Server 2000 2 May 14th, 2005 12:02 PM
Urgent: Implement Cascade Delete through Code rcmetta BOOK: Professional Crystal Reports for VS.NET 0 June 7th, 2004 12:49 AM
cascade Ibn_Aziz C# 1 February 24th, 2004 11:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.