views:

201

answers:

1

I have a Delphi 2010 ADO program that has a DBGrid. Its dataset selects from an Access query. The query has a column defined as, CStr(Amount*UnitCount)+" "+Unit. The query works fine in Access. But the DBgrid refuses to show the values for this column

+1  A: 

You'll want to define a calculated field in the TDataset descendant that is connected to your grid, and then implemented the calculation for that field in the OnCalcFields event.

Brave Cobra
This works, of course. But it doesn't make sense that if the db engine does the translation in the query, why the control just doesn't see the query as presented and display the values.
Ken Lange
That depends on whether you want Delphi to do the calculation or the DB Engine. If you want the DB engine to do it, then rewrite your query as "select a, b, (a+b) as thesum from mytable". That way the result including the calculation is done by the DB engine and there is no need for the calculated field in delphi, however it could be harder to insert/update new data into the table. Depending on the implementation of the TDataset descendant, it might not recognize the calculated field and thus leaving your dataset not update-able, but 'll have to test that one. The choice is yours.
Brave Cobra