如何删除数据集关系?
我怎样才能做到这一点?我尝试过 DataSet.Relations.Clear(),但它不起作用。有什么想法吗?
How can I do that? I have tried DataSet.Relations.Clear(), but it doesn't work. any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是从数据库设计的角度来回答。听起来您的模型有一个外键约束,可以防止在有子记录时删除父记录。根据您使用的工具和您拥有的权限(以及您希望影响数据模型完整性的程度),您也许能够删除此约束。这会在子表中留下孤立数据。您也许还可以在父级上编写一个删除触发器,该触发器首先删除所有子级。或者,您可以构建代码来查找子级,先删除它们,然后删除父级。
I'm only answering from a database design perspective. It sounds like your model has a foreign key constraint that prevents deleting a parent record when it has children. Depending on what tools you are using and what permissions you have (and how much you want to affect the integrity of the data model) you might be able to remove this constraint. This would leave orphaned data in the child table. You might also be able to write a delete trigger on the parent that goes and deletes all the children first. Alternately you can structure your code to find the children, delete them first then delete the parent.
这对我有用:
按照此代码片段删除任何可能阻止从数据集中删除表的外键约束:
This worked for me:
Follow that up with this snippet to remove any foreign key constraints that might prevent removing tables from the dataset: