|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataAdapter.Update PB with a new databaseWith a NEW database, I have an auto-generate DataSet ()with menu "Add new DataSource...") with two DataTables, parentTable and childTable, and a relation between them. I fill these two tables with five records, then try to update database with these records, using the autogenerate parentDataTableTableAdapter and childTableTableAdapter, after having set a ForeignKeyConstraint on childTable, related to the relation. Some problems appear when I update a new created database. First problem : when I use parentDataTableTableAdapter.Update(), an exception is thrown, telling me that a row ID is already present in parentTable. The problem comes from the autoincrementseed of id column that is set to 0, althrough it is set to 1 in the database. So then first row is updated, its id in DataSet is set to 1, already in table. To avoid this feature, I found two solutions : - Set autoincrement seed to 1. But, a new problem can appear if one record is already in database - Set dataSet.EnforceConstraints to false In this last case, I have a new problem appearing : after the parentTable update, the child table foreign key is set to the last updated row of parentTable. This trouble is certainly due to MSDN advice (ForeignKeyConstraint) : "Constraints are not enforced unless the EnforceConstraints property is set to true" But update works fine when the database has already some records ! So, please, how can I do to avoid all these problems ? Thanks in advance, FG |
|||||||||||||||||||||||