Hello everyone.
Made a search, and i've seen there are no threads about this issue.
My problem is a syntax-related one (as most are):
So, i got a Microsoft Access database file, which i linked with my c++ builder. Using a TDataSource, TTable, TDBGrid and a TDBNavigator, i managed to display the contens of my database file .accdb (which contained only 1 table) to my TDBGrid.
Here comes the tricky part:
I added another column from within C++ Builder which i want to fill up with information based on what i already have in the original table. (like, if i had two columns, A and B, filled with numbers, column C would contain the average between the values from columns A and B within the same row; just as an idea). How do i 'tell' c++ to 'take' information, let's say from Column X and Row Y, and replace it or put it back in in another row/column?
Thanks a lot.
borland c++ builder 5, dbgrid question
Started by totonex, Mar 23 2009 10:53 AM
2 replies to this topic
#1
Posted 23 March 2009 - 10:53 AM
|
|
|
#2
Posted 23 March 2009 - 11:32 AM
That will be specific to how the dbgrid allows you to access information. I don't think anyone on this forum actually uses C++ builder.
#3
Posted 27 March 2009 - 10:40 AM
First of All, you are recommended against using BDE because Borland is not updating it any more. You should be able to use its ADO counterpart.
Regardless, here is one way of doing what you intend:
Click the TTable object in your form designer, right click, select "Fields Editor", add those fields you want to display or use , and then right click somewhere in the Fields Editor and select "New..." from the popup menu.
Name the field you want to add, its type , etc and remember to change field type as Calculated. Now you have the calculated field but you'll still need to specify how to calculate it. Select the Table object in the Form Designer, F11 to show the object inspector if it's not already there, go to events tab, find the OnCalcFields event, double click it to create a handler for it.
However, for a job as simple as this, I will use a Query, with SQL something like
Regardless, here is one way of doing what you intend:
Click the TTable object in your form designer, right click, select "Fields Editor", add those fields you want to display or use , and then right click somewhere in the Fields Editor and select "New..." from the popup menu.
Name the field you want to add, its type , etc and remember to change field type as Calculated. Now you have the calculated field but you'll still need to specify how to calculate it. Select the Table object in the Form Designer, F11 to show the object inspector if it's not already there, go to events tab, find the OnCalcFields event, double click it to create a handler for it.
void __fastcall TForm1::ADOTable1CalcFields(TDataSet *DataSet)
{
#define ____FC(fld) DataSet->FieldByName(#fld)->AsCurrency
____FC(average)=(____FC(fld1) + ____FC(fld2))/2;
#undef ____FC
}
However, for a job as simple as this, I will use a Query, with SQL something like
SELECT *, (fld1+fld2)/2 AS average FROM mytable


Sign In
Create Account


Back to top









