1

How can I do that? I have tried DataSet.Relations.Clear(), but it doesn't work. any ideas?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Brezhnews
  • 365
  • 2
  • 6
  • 13

2 Answers2

0

This worked for me:

for (int i = DS.Relations.Count - 1; i >= 0; i--)
  DS.Relations.Remove(DS.Relations[i]);

Follow that up with this snippet to remove any foreign key constraints that might prevent removing tables from the dataset:

for (int i = DS.Tables.Count - 1; i >= 0; i--)
{
  var table = DS.Tables[i];
  for (int constraint = table.Constraints.Count - 1; constraint >= 0; constraint--)
    if (table.Constraints.CanRemove(table.Constraints[constraint]))
      table.Constraints.Remove(table.Constraints[constraint]);
}
Bill Roberts
  • 1,127
  • 18
  • 30
0

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.

Tod
  • 8,192
  • 5
  • 52
  • 93