|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Q: Relationships and exceptionsCan anybody explain to me what I'm doing wrong or misunderstood in the following: I have two tables, for example, customers and orders. I have loaded these into a dataset. I have also created a relation between these two tables using the Relation keyword e.g. ds.Relationships.Add("Customers_Orders", _ ds.Tables("Customers").Columns("CustomerID"), _ ds.Tables("Orders").Columns("CustomerID"), True) I populate both tables with data. Everything works ok. However, when I choose a row from the Customers tables and try to delete it as follows: Try row.Delete() ' where row has child rows in the Orders table Catch ex Exception MessageBox(ex.Message) End Try The thing is that no exception is thrown!!! I was expecting one to be thrown. Have I missed something obvious? Thanks for any help in advance Geoff Hi,
Show quoteHide quote "Geoff" <nodamnspam@email.com> wrote in message When you add a DataRelation, then there's also a ForeignKeyConstraint added news:95idnXKcZpocJnDenZ2dnUVZ8qednZ2d@pipex.net... > Hi > > Can anybody explain to me what I'm doing wrong or misunderstood in the > following: > > I have two tables, for example, customers and orders. I have loaded these > into a dataset. I have also created a relation between these two tables > using the Relation keyword e.g. > > ds.Relationships.Add("Customers_Orders", _ > ds.Tables("Customers").Columns("CustomerID"), _ > ds.Tables("Orders").Columns("CustomerID"), True) > > I populate both tables with data. > > Everything works ok. However, when I choose a row from the Customers > tables and try to delete it as follows: > > Try > row.Delete() ' where row has child rows in the Orders table > Catch ex Exception > MessageBox(ex.Message) > End Try > > The thing is that no exception is thrown!!! I was expecting one to be > thrown. Have I missed something obvious? to the child table. The ForeignKeyConstraint has a property 'DeleteRule'. By default that property is set to Rule.Cascade. So when you delete a parent row, child rows are deleted too and therefore there is no reason for an Exception. You can change this behaviour, eg. : ds.Relations("Customers_Orders").ChildKeyConstraint.DeleteRule = Rule.None If you delete a parent row now and the parent has child rows, it will throw an exception, because the child rows would become orphaned. HTH, Greetings Show quoteHide quote > > Thanks for any help in advance > > Geoff > Thanks Bart!
Show quoteHide quote "Bart Mermuys" <bmermuys.nospam@hotmail.com> wrote in message news:OU6cqXwLGHA.532@TK2MSFTNGP15.phx.gbl... > Hi, > > "Geoff" <nodamnspam@email.com> wrote in message > news:95idnXKcZpocJnDenZ2dnUVZ8qednZ2d@pipex.net... >> Hi >> >> Can anybody explain to me what I'm doing wrong or misunderstood in the >> following: >> >> I have two tables, for example, customers and orders. I have loaded these >> into a dataset. I have also created a relation between these two tables >> using the Relation keyword e.g. >> >> ds.Relationships.Add("Customers_Orders", _ >> ds.Tables("Customers").Columns("CustomerID"), _ >> ds.Tables("Orders").Columns("CustomerID"), True) >> >> I populate both tables with data. >> >> Everything works ok. However, when I choose a row from the Customers >> tables and try to delete it as follows: >> >> Try >> row.Delete() ' where row has child rows in the Orders table >> Catch ex Exception >> MessageBox(ex.Message) >> End Try >> >> The thing is that no exception is thrown!!! I was expecting one to be >> thrown. Have I missed something obvious? > > When you add a DataRelation, then there's also a ForeignKeyConstraint > added to the child table. The ForeignKeyConstraint has a property > 'DeleteRule'. By default that property is set to Rule.Cascade. So when > you delete a parent row, child rows are deleted too and therefore there is > no reason for an Exception. > > You can change this behaviour, eg. : > > ds.Relations("Customers_Orders").ChildKeyConstraint.DeleteRule = Rule.None > > If you delete a parent row now and the parent has child rows, it will > throw an exception, because the child rows would become orphaned. > > > HTH, > Greetings > > >> >> Thanks for any help in advance >> >> Geoff >> > >
DateDiff function returning incorrect results in asp.net 2.0 vb
SOAP Body Time conversion and vb.net Just-In-Time Debugging????? Find specific pattern in a string SImple ADO.Net problem .net 2005 cannot show menu ! Msg Box not displaying messages Error Logging? Howto Transfer data from the DataTable into a SQL Database |
|||||||||||||||||||||||