ClientDataSet cannot update fields with null value (I)

18.4.05

The second bug report has been kept in my In-Tray over 4 months but I found no way to fix it. Users complain that the custom dataSet (derived from TClientDataSet) is failed to update fields with null value.

For example, a record with below fields and values:
[ID].....[NAME]...[AGE]
.S100... PETER ....10


Now I modify the record by clear Name and Age:

cds.FindField('NAME').value := '';
cds.FindField('AGE').value := null;
cds.Post;
cds.ApplyUpdates(0);

You may think both NAME and AGE are clear (although empty string and null are not the same). Open the database and find out the record, however, the result is different. Only Name value is clear as empty string.

Modify the codes:

cds.FindField('NAME').value := null;
cds.FindField('AGE').clear;
cds.Post;
cds.ApplyUpdates(0);


This time both NAME and AGE are failed to be updated.
Do you know why? I checked the custom dataSet almost every line... but all looked like fine and no clue found. Both Delphi 6 & 7 have the same result. Even posted the question on the newsgroup 4 months ago but seemed no one met the same problem. (Why is me!!!)

Tell you the bug more in the next post.


Comments:
A few tips:

1. Don't assign Field.Value := null. Use Field.Clear instead whenever you want to assign NULL.

2. Do you have a CDS.OnReconcileError assigned? If not, do so and find out if any errors are being reported.

3. Are you doing any custom processing on the server-side. Specifically in the DSP.BeforeUpdateRecord event?

If you still need help, email me a small test project and I'll take a look.

There are so many thinks that can happen... well Dan pointed out three... one more could be the destination database... maybe a silly question but are you accepting nulls on those fields at the destination table?. Maybe a Index is triggering the error..

Thanks Dan and Albert!
I should state clearly that it is about XML datapacket in MIDAS.

Post a Comment

<< Home