You could create a trigger instead of the cascade-delete, for example(MS SQL-Server, untested): CREATE TRIGGER dbo. TrDeleteTableB ON dbo. TableA FOR DELETE AS DELETE FROM TableB WHERE (MessageID IN (SELECT MessageID FROM DELETED WHERE (NOT EXISTS (SELECT * FROM TableA WHERE (TableA.
MessageID = DELETED. MessageID))))) Another idea is to extend your typed Dataset. If you want to extend the functionality you can't change the generated classes in the DatesetName.designer.Cs/vb (it will be recreated on any change) but the file without designer in its name(create it if it not exists).
Then you have to extend the partial DataTable-class(look in the designer-file if you don't know the exact name, it's normally f. E TableBDataTable ) Have a look at following code to see what I mean, I haven't tested it but I hope you take my point: Partial Class Datset1 Partial Class TableBDataTable Private Sub TableB_RowDeleting(ByVal sender As Object, ByVal e As TableBRowChangeEvent) Handles Me. TableBRowDeleting If e.
Action = DataRowAction. Delete Then '*** check here if there is another TableARow with this MessageID ***' e.Row.RejectChanges() End If End Sub End Class End Class.
You could create a trigger instead of the cascade-delete, for example(MS SQL-Server, untested): CREATE TRIGGER dbo. TrDeleteTableB ON dbo. TableA FOR DELETE AS DELETE FROM TableB WHERE (MessageID IN (SELECT MessageID FROM DELETED WHERE (NOT EXISTS (SELECT * FROM TableA WHERE (TableA.
MessageID = DELETED. MessageID))))) Another idea is to extend your typed Dataset. If you want to extend the functionality you can't change the generated classes in the DatesetName.designer.Cs/vb (it will be recreated on any change) but the file without designer in its name(create it if it not exists).
Then you have to extend the partial DataTable-class(look in the designer-file if you don't know the exact name, it's normally f.e. TableBDataTable). Have a look at following code to see what I mean, I haven't tested it but I hope you take my point: Partial Class Datset1 Partial Class TableBDataTable Private Sub TableB_RowDeleting(ByVal sender As Object, ByVal e As TableBRowChangeEvent) Handles Me.
TableBRowDeleting If e. Action = DataRowAction. Delete Then '*** check here if there is another TableARow with this MessageID ***' e.Row.RejectChanges() End If End Sub End Class End Class.
I am attempting to do this in the dataset only. I do not intend to update SQL with these changes. (I won't bore you with the reason why) – Bremer May 4 at 20:33 The delete rule is also on the database side.
Then you have only the option to remove the cascade-delete and check in the application if the child must be deleted or not. – Tim Schmelter May 4 at 20:38 That's what I feared. Thanks.
– Bremer May 4 at 21:25 @Bremer: I've had another idea and edited my answer, have a look. – Tim Schmelter May 4 at 22:08 I came up with the same solution myself and it works great! Actually, I added my event handler code in a class that’s consuming the dataset.
Your placement in a partial class is even better. Thanks! – Bremer May 47 at 13:58.
I have a relationship between Table A and Table B on the MessageID column. The delete rule is set to Cascade. I cannot change the design of these tables, it is what it is.
Table A contains two records with MessageID 1. If I delete only one of those, the child record is deleted from Table B, creating an orphan in the second parent table. Is there a way to only delete if there are no other parent records sharing the MessageID?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.