Hello! I have a base form to perform invoices and similar documents. I
must use a IBDataSet connected to a DBGrid, so I can't use aggregated
fields or grids with the "sum" facility.
What I need is very basic: as the user enters or modifies lines in the
grid, just show the total of the lines at the foot of the grid.
So what is your advice to sum all records in a small query? Being an
invoice, the detail set will never be greater than, lets say, 300
lines... (to say something very big!!)
What I'm doing now is: remember the cursor position, disable controls,
and in AfterPost event, just do a "while not eof" and add all the
values, and then put the cursor where it was before.
Is that the proper way to do it? I guess there must be better ways!!
A IBQuery in the same transaction with "select Sum(myfield)" would be ok?
I just want to know a "good way" to do it!!!
I hope I'm clear with my question!
Sergio
>> Is that the proper way to do it? I guess there must be better ways!!
>> A IBQuery in the same transaction with "select Sum(myfield)" would be ok?
>
> Yes, but use an IBSQL, it is faster. Even IBDataset is slightly faster than
> IBQuery. As logn as you can look up on an indexed field should be more than fast.
>
>> I just want to know a "good way" to do it!!!
>
> An alternative is to use client datasets. Drive things to the grid the a CDS
> and then in the AfterPost cloen the cursor of the CDS with a second one and loop
> it, no need for the bookmarking disable controls etc.
Thanks for the answer Jeff! Can't use ClientDataSets...
So how would you do it with IBX? I want and advice from an expert!! :)
1) A separate query with "select sum(amount)..." ? Don't like too much
the idea of performing the sum in the server side...
2) A "while not eof" with the same DataSet I'm using (disabling controls
etc)?
3) Or perhaps, having a private var and just do (on BeforePost)
MySUM :=
MySum -
DS_Detail.FindField('amount').OldValue +
DS_Detail.FindField('amount').Value;
This way I don't need to iterate the dataset each time I modify
something...
Sorry if this is a silly question... Its easy to make it work, but I
always want to know the "best way" to do something
Sergio
sergio gonzalez wrote:
> Hello! I have a base form to perform invoices and similar documents. I
> must use a IBDataSet connected to a DBGrid, so I can't use aggregated
> fields or grids with the "sum" facility.
>
> What I need is very basic: as the user enters or modifies lines in the
> grid, just show the total of the lines at the foot of the grid.
>
> So what is your advice to sum all records in a small query? Being an
> invoice, the detail set will never be greater than, lets say, 300
> lines... (to say something very big!!)
>
> What I'm doing now is: remember the cursor position, disable controls,
> and in AfterPost event, just do a "while not eof" and add all the
> values, and then put the cursor where it was before.
>
> Is that the proper way to do it? I guess there must be better ways!!
> A IBQuery in the same transaction with "select Sum(myfield)" would be ok?
>
Yes, but use an IBSQL, it is faster. Even IBDataset is slightly faster than
IBQuery. As logn as you can look up on an indexed field should be more than fast.
> I just want to know a "good way" to do it!!!
An alternative is to use client datasets. Drive things to the grid the a CDS
and then in the AfterPost cloen the cursor of the CDS with a second one and loop
it, no need for the bookmarking disable controls etc.
>
> I hope I'm clear with my question!
>
> Sergio
--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted corridors of Whitehall.
(Fish)