Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 15th, 2005, 01:11 PM
Friend of Wrox
 
Join Date: Mar 2005
Location: , , .
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to prompt user if they try to delte wrong valu

How to prompt user if they try to delete a record from datagrid which
has relationship with other table? I created a editable datagrid and
want to inform user if they try to delete a record that has reletions with other tables. I be happy if some one help me how i can do this in asp.net .Thanks

http://i5.photobucket.com/albums/y18...7/19932c0e.jpg (db reletion ship)

Here is my delete code :

Code:
Private Sub DataGridMatch_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGridPlayer.DeleteCommand
        Dim MyCommand As SqlCommand
        Dim DeleteCmd As String = "Delete From players Where playerno = " & e.Item.Cells(2).Text
        MyCommand = New SqlCommand(DeleteCmd, MyConnection)
        MyCommand.Connection.Open()
        MyCommand.ExecuteNonQuery()
        MyCommand.Connection.Close()
        DataGridPlayer.EditItemIndex = -1
        BindDataGridPlayer()


    End Sub
Reply With Quote
  #2 (permalink)  
Old June 15th, 2005, 03:27 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,346
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You have a few options. You can write a query to see if the ID exists in any other table and warn the user. Or you can let the delet run and trap the sql error. Or you can put cascading deltes in your DB and let the delete run.

Reply With Quote
  #3 (permalink)  
Old June 16th, 2005, 08:23 AM
Friend of Wrox
 
Join Date: Mar 2005
Location: , , .
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by jbenson001
 You have a few options.  You can write a query to see if the ID exists in any other table and warn the user.  Or you can let the delet run and trap the sql error.  Or you can put cascading deltes in your DB and let the delete run.

Thank u for u reply. well i do not want to vilote the db reletionship so i do not want to user cascade delete. How i can trap sql error. i be happy if u show me how.Thanks
Reply With Quote
  #4 (permalink)  
Old June 16th, 2005, 08:53 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,346
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Use the Try...Catch..End Try statement.

See the help in VS.

Reply With Quote
  #5 (permalink)  
Old June 17th, 2005, 08:32 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by method
 well i do not want to vilote the db reletionship so i do not want to user cascade delete.

Method, I think you missed the point of cascade deletes. If you build tables that are related but do not place foreign keys on them you run the risk of deleting parent rows and leaving orphaned child rows. So you add on foreign keys. Of course, now you have relationship integrity. If you want to delete parent rows you must delete the child rows first in order to avoid violation of the relationship.

The whole intent for cascading deletes is to allow you to support referential integrity thru foreign key relationships but allow you to delete parent rows without having to worry about first deleting the child rows. The cascade delete does this for you.

You have to ask yourself the question: "Is it acceptable for a user to delete something that has dependant information that will also be deleted?"

There are often cases where the answer is NO because you need to maintain some history of information (ex. Product Orders). Then you have to design your database to support additional conditions on the tables such as adding an "Active" field to a "Products" table to indicate that the product is or is not active any more. That way your application can see the row still exists but we shouldn't include it in lists of active products. In this case, you would not want cascade delete on the foreign key to the Products table because you want the database to error out if you DID try to delete a product that had order history.

So in the end you are back to the suggestion Jim made which is to
A) Query the database and see if circumstances prevent a valid delete
B) Try the delete and catch the Sql exception

-Peter
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to prompt user for password Imtiaz Ahmed Classic ASP Professional 1 June 21st, 2007 05:28 PM
How to perform calculation on datagrid column valu Giri C# 1 August 16th, 2006 06:32 AM
prompt user before exiting sandeep Javascript How-To 1 September 5th, 2005 01:42 PM
ACCESS Programming DELTE problem dvlnblk2000 Access 1 September 29th, 2004 07:50 AM
How to prompt user Internet Connection Wizard? joan VS.NET 2002/2003 0 September 30th, 2003 10:31 PM



All times are GMT -4. The time now is 02:44 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.