J
Jeff Cooper
Hi folks,
I have a DataSet in which I have a couple of DataTables. At some point in
my code (vb) I'd like to remove one of the tables. The tables, call 'em DT1
and DT2 are created have a relation between them:
myDataSet.Relations.Add("DT1_DT2", Results.Tables(0).Columns(0),
Results.Tables(1).Columns(0), True)
Also, I have a PrimaryKey placed on table DT2 so no duplicate rows get
inserted:
k(0) = DT2.Columns(0)
DT.PrimaryKey = k
So far so good. I do a bunch 'o queries, get a bunch of data. Now, I'd like
to remove DT2 from the myDataSet.Tables collection:
myDataSet.Relations.RemoveAt(0)
myDataSet.Tables.RemoveAt(0)
The second line above gives me an error: "Server was unable to process
request. ---> System.ArgumentException: Cannot remove unique constraint
'Constraint1'. Remove foreign key constraint 'DT1_DT2' first. at
System.Data.UniqueConstraint.CanBeRemovedFromCollection.... etc etc."
As you can see above, I DID remove the relationship.
I tried modifying the above code as follows:
myDataSet.Relations.RemoveAt(0)
myDataSet.Tables(0).PrimaryKey = Nothing 'see if this fixes anything
myDataSet.AcceptChanges() 'try this too.
myDataSet.Tables.RemoveAt(0)
Neither worked.
How can I delete a table from a dataset on which I have created then removed
a relation? You may notice in my original relations.add statement, I have
createConstraints set to True. I think I need that because some of my
queries should only get populated into DT2 where they have existing parents
in DT1. I don't see any "Constraint" or "ForeignKeyConstraint" property or
collection anywhere, so I'm at a loss as to how to get rid of it. Any help
would be much appreciated.
Thanks,
Jeff
I have a DataSet in which I have a couple of DataTables. At some point in
my code (vb) I'd like to remove one of the tables. The tables, call 'em DT1
and DT2 are created have a relation between them:
myDataSet.Relations.Add("DT1_DT2", Results.Tables(0).Columns(0),
Results.Tables(1).Columns(0), True)
Also, I have a PrimaryKey placed on table DT2 so no duplicate rows get
inserted:
k(0) = DT2.Columns(0)
DT.PrimaryKey = k
So far so good. I do a bunch 'o queries, get a bunch of data. Now, I'd like
to remove DT2 from the myDataSet.Tables collection:
myDataSet.Relations.RemoveAt(0)
myDataSet.Tables.RemoveAt(0)
The second line above gives me an error: "Server was unable to process
request. ---> System.ArgumentException: Cannot remove unique constraint
'Constraint1'. Remove foreign key constraint 'DT1_DT2' first. at
System.Data.UniqueConstraint.CanBeRemovedFromCollection.... etc etc."
As you can see above, I DID remove the relationship.
I tried modifying the above code as follows:
myDataSet.Relations.RemoveAt(0)
myDataSet.Tables(0).PrimaryKey = Nothing 'see if this fixes anything
myDataSet.AcceptChanges() 'try this too.
myDataSet.Tables.RemoveAt(0)
Neither worked.
How can I delete a table from a dataset on which I have created then removed
a relation? You may notice in my original relations.add statement, I have
createConstraints set to True. I think I need that because some of my
queries should only get populated into DT2 where they have existing parents
in DT1. I don't see any "Constraint" or "ForeignKeyConstraint" property or
collection anywhere, so I'm at a loss as to how to get rid of it. Any help
would be much appreciated.
Thanks,
Jeff