DoronD
DoronD

Reputation: 1

DataSetProvider error?

I have DBGrid->DataSource->ClientDataSet->DataSetProvider->CustomDataSet.

(I use my own custom dataset at the end because we don't have a direct connection to a database...we have a pointer to a certain type that we can change at anytime.)

Either way, the dataset and clientdataset work great. I recently encountered a problem.

I have a Primary key named ID in the database. When I do multiple NEW inserts I handle it by calling ClientDataSet->Append() and then set the ID value of each new row to the inverse number of the last row + 1.
(IE: If there are 935 rows currently, the new row ID will be -936)
This way, I fix the Key Violation error that occurs if no ID is set since it is a primary key, and the DB ID gets inserted when I save.

Now, for where my problem is:
I already have a blank row in the database.
I have a uniquekey set in the DB itself so it cannot take in two rows containing the same data (so can't have TWO blank rows, etc).

I have 935 rows in the DB already, and row 935 is blank.
I insert 3 new rows, and press save.
For each, I get an error in the OnUpdateError callback saying "Duplicate Row".

That means I have rows 936, 937, and 938 in the ClientDataSet, but not my CustomDataSet or DB since nothing was saved because they are in error.

If I delete row 937, everything in the UI side looks fine.
If I go to save again however, the rows that are returned to me in error(and that are stored in the DataXML file) are rows 936 and 938.

Shouldn't the DataSetProvider have updated itself when I deleted the 937 row from the ClientDataSet? I know that row 938 IS in error...but it does not exist anymore.

If 937 was erased, then 938 becomes 937.

I've been searching for help on this for a while, but nothing seems to resolve it.

Upvotes: 0

Views: 477

Answers (1)

Wim Schilleman
Wim Schilleman

Reputation: 11

I presume you use an autoinc field in your DB. I recently found that it is possible to save your new rows without applying a value to your key field. In the clientdataset and customdataset you have to remove the required flag for your keyfield and remove the InUpdate flag for the datasetprovider. I think that will solve your problem.

see the following link http://www.drbob42.com/examines/examinC0.htm

Upvotes: 1

Related Questions