Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
|
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 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 June 15th, 2005, 01:11 PM
Friend of Wrox
 
Join Date: Mar 2005
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
 
Old June 15th, 2005, 03:27 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
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.

 
Old June 16th, 2005, 08:23 AM
Friend of Wrox
 
Join Date: Mar 2005
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
 
Old June 16th, 2005, 08:53 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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

See the help in VS.

 
Old June 17th, 2005, 08:32 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
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





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





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