Troubleshooting

Errors and the Reasons for Their Occurrence

You create a DataSet object and fill it with records from one of the database tables. Assume that the table has a primary key column called PrID. You change the value of a PrID from 10 to 20 (assuming that there is no record with the PrID 20). You then create a new row with PrID 10. This process results in an error.

The error is generated because the DataSet processes the requests in a sorted order. The DataSet always processes the inserts, updates, and deletes in that order. Therefore, the insertion of a new row happens before the old row is updated and gives rise to the error. If you want to avoid this, you will have to force updates before adding the new row.

When you execute a ...

Get Special Edition Using C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.