Home > Back-end >  OnCalcFields method how to do
OnCalcFields method how to do

Time:09-29

Procedure Tydxxgl. FormShow1;
The begin

Qry1. Close;
Qry1. SQL. Text:='select a. *, zt as zhuangtai from ydxx a';
Qry1. Open;

The end;



Procedure Tydxxgl. Qry1CalcFields (DataSet: TDataSet);
The begin
If qry1. FieldByName (' zt) AsString='1' then
The begin
Qry1. FieldByName (' zhuangtai). AsString:='reservations';
The end;
If qry1. FieldByName (' zt) AsString='2' then
The begin
Qry1. FieldByName (' zhuangtai). AsString:='has check in;
The end;
If qry1. FieldByName (' zt) AsString='3' then
The begin
Qry1. FieldByName (' zhuangtai). AsString:='cancelled';
The end;
The end;

I want to achieve from the database query, then assignment, and displayed in the dbgrid, such as the database state is 1, I want to show in the dbgrid "in the book", this is the code, what is going wrong, how to still show is 1? I am a novice,,,,,,,

CodePudding user response:

You can create a view in SQL, SQL to transformation,

CodePudding user response:

I'm using the access database

CodePudding user response:

This way is wrong, you see the SQL statements you 'zhuangtai' field and 'zt' field is the same, get yourself or useless,
You should be a new field, type is calculated fields, to use this new field to calculate,
Like this:
Var
Newfield: TStringField;
The begin
Qry1. Close;
Qry1. SQL. Text:='select a. * from ydxx a';//don't need a zt as zhuangtai
Qry1. Open;
. .
Newfield:=TStringField. Create (qry1);
Newfield. Fieldname:='ztcalc';
Newfield. Fieldtype:=fCalcField;//this property may be, I also can't remember, you check
Qry1. Fields. The add (newfield);
.

Try yourself,

Or in TQuery component in the design of field make this custom fields with the editor, so you don't need the code above,
  • Related