开发者

c# DataSet with 2 tables, how to delete a row from one it will delete a row from the other?

I use Visual Studio 2010

I have a DataSet with 2 tables

one (MainList) has type, name, path, parameter the other (UpadteList) has path, hash, date

I added files to this list and it work with out problem, now I have the following

when I add file type "update" it will be "Update","My Program", "PATH-TO-/my.setup.exe","/minimized"

if it was type "Update" the following data goes to (UpdateList) "PATH-TO-/my.setup.exe","asdfwefwfgg3r34t34t34t","2010-09-01"

I want when a row in th开发者_JAVA百科e (MainList) deleted and a row with the same path in (UpdateList) exsist it will deleted too

should I use loop or (I saw) in dataSet properties use Relations

what is the best approach ?

with loops I got into some ugly bugs that delete everything in the Mainlist!

note: I use XML to store data (the data is not big)


IMO, you have two choices

  1. Use DataTable constraints such as ForeignKeyConstraint with DeleteRule=Cascade settings.
  2. Use RowDeleted/RowDeleting event on MainList data-table to look up and delete the corresponding row in other table.


I think that code is arguably the wrong place to deal with data consistency. I'd do it in the database, either in a stored procedure or, if you're using SQL Server, possibly with cascading deletes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜