Remove Dataset Constraints

G

Guest

I am trying to remove a set of tables, relations and constraints from a dataset, however I get an error: "Collection was modified, enumeration operation may not execute". I create the dataset with three tables. The tables are created in VB .Net code by sending an SQL criteria string to SQL Server to create 3 DataAdapters. I then use the DataAdapters to populate the dataset, I create constraints (primary keys) and relationships amoung the 3 tables. I then show the data in the tables on a form. The user may want to see a different set of records on the form, so I need to repopulate the dataset with the same tables that have new records (I run a new query) that meet the new criteria. Before repopulating the dataset with the new table data, I clear out the constraints with the following code, but I get the error above on the first "Next cs" line. Is this the best way to clear the dataset? Can you tell me why I am getting this error?

Dim t As DataTabl
Dim cs As Constrain

'If the find criteria form has been displayed more than once remove
'relations, constraints and tables in datase
If ifrmCounter > 1 The
'Remove constraint
For Each cs In tCustomerCategoryTable.Constraint
If tCustomerCategoryTable.Constraints.CanRemove(cs) The
tCustomerCategoryTable.Constraints.Remove(cs
End I
Next c

For Each cs In tCategoryTable.Constraint
If tCategoryTable.Constraints.CanRemove(cs) The
tCategoryTable.Constraints.Remove(cs
End I
Next c

dsDataSet11.Relations.Clear(
dsDataSet11.Tables.Clear(

End I
 
B

Brad Williams

I don't understand why you're wanting to remove the constraints, would it
help you to disable all constraints temporarily with
EnforceConstraints=false?

Brad Williams


Gary said:
I am trying to remove a set of tables, relations and constraints from a
dataset, however I get an error: "Collection was modified, enumeration
operation may not execute". I create the dataset with three tables. The
tables are created in VB .Net code by sending an SQL criteria string to SQL
Server to create 3 DataAdapters. I then use the DataAdapters to populate the
dataset, I create constraints (primary keys) and relationships amoung the 3
tables. I then show the data in the tables on a form. The user may want to
see a different set of records on the form, so I need to repopulate the
dataset with the same tables that have new records (I run a new query) that
meet the new criteria. Before repopulating the dataset with the new table
data, I clear out the constraints with the following code, but I get the
error above on the first "Next cs" line. Is this the best way to clear the
dataset? Can you tell me why I am getting this error?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top