Board index » delphi » Is there any way to modify value of the server-calculated field

Is there any way to modify value of the server-calculated field

I have a field in dataset that has no corresponding field in the table, that
is it is calculated by stored proc.
Now I need to change its value in my app (I use it as cache field for
calculations and want to recalc it only when fields on which it depends are
changed - thus I can not use field of fkCalculated kind)

But ADO throws an exception when I try to post record.

my dataset has lock type of ltBatchOptimistic and cursortype ctKeyset

thanks

 

Re:Is there any way to modify value of the server-calculated field


Quote
"Konstantin Krivtsov" <k...@chat.ru> wrote in message

news:3beacf30$1_2@dnews...

Quote
> I have a field in dataset that has no corresponding field in the table,
that
> is it is calculated by stored proc.
> Now I need to change its value in my app (I use it as cache field for
> calculations and want to recalc it only when fields on which it depends
are
> changed - thus I can not use field of fkCalculated kind)

Post obviously wouldn't work 'cause there's no place to put the value from
the calculated field back to the database.
The way about this may depend on what do you use to show your data and what
type of calculated field is it. If the value can always be reproduced by
some sort of formula, OnCalcField should do a trick. If that's not possible,
and you use grid to display your resultset, you may try to play with
OnDrawDataCell. The calculated value could be stored in an object or a
record per data record. This may a bit tougher since you'd need to maintain
a TStringList with pointers to a series of record to object pointers. Grids,
other than DBGrid, sometimes offer Data property, which acts as pointer to
an instance of your storage objects.
Easier way would be to use an in-memory dataset, which you load with data
from regular dataset, add fields you need and do edit/insert/post just like
with "real" stuff. You may want to check out the one from DevExpress.

rb

Re:Is there any way to modify value of the server-calculated field


Quote
"rb" <ra...@killspam-videotron.ca> wrote in message

news:3becbc76$1_2@dnews...

Quote

> Post obviously wouldn't work 'cause there's no place to put the value from
> the calculated field back to the database.

Well, my guess was that in batch-update mode this should work until I'll try
to execute UpdateBatch.
Since I never call it, I thought that all would be ok. But it isn't.

Thanks for the suggestion about inmemory datasets though.

Re:Is there any way to modify value of the server-calculated field


Batch update or not, it is still considered "writing" to database. Think how
would your dataset react on a simple aggregate query:

    select ClientCode, sum( OrderTotal ) as TotalSales
    from Orders

Your dataset can read TotalSales field, but it's obvious that its origin is
unknown or non-existent. That's why it doesn't work in this batch update
mode either.

I must admit though that this is rather odd behaviour when it comes to
disconnected datasets. It is obvious that some sort of storage had to be
created for the calculated field to be displayed. It's beyond me why
wouldn't I be able to write to it *if* my dataset is disconnected. Most
likely too many variable to track.

rb

Quote
"Konstantin Krivtsov" <k...@chat.ru> wrote in message

news:3bed12f4$1_2@dnews...
Quote

> "rb" <ra...@killspam-videotron.ca> wrote in message
> news:3becbc76$1_2@dnews...

> > Post obviously wouldn't work 'cause there's no place to put the value
from
> > the calculated field back to the database.

> Well, my guess was that in batch-update mode this should work until I'll
try
> to execute UpdateBatch.
> Since I never call it, I thought that all would be ok. But it isn't.

> Thanks for the suggestion about inmemory datasets though.

Other Threads