I want to calculate all fields and to total field. How can I do this. I did this with sql command. but I don't know how to update dbgrid everytime. my code :
procedure TForm1.Button1Click(Sender: TObject);
ADOQuery1.SQL.text:='select names,big1,small1,black1,big2,small2,big3, ((big1+small1+black1+big2+small2+big3)*0.35) as total from adlar7v';
ADOQuery1.FieldValues['big1'] + ADOQuery1.FieldValues['small1'] +
ADOQuery1.FieldValues['black1'] + ADOQuery1.FieldValues['big2'] +
ADOQuery1.FieldValues['small2'] + ADOQuery1.FieldValues['big3'];
when I run this code first time working second time changes doesn't appear db grid
Use the Object Inspector to set up an AfterPost handler on your AdoQuery1:
procedure TForm1.ADOQuery1AfterPost(DataSet: TDataSet); begin AdoQuery1.Refresh; end;
Then, after you save a change to one of the numeric columns in the grid, the AdoQuery1.Refresh will cause the data to be retrieved again from the server, and that will cause the server to recalculate the "Total" column. The fact that it isn't doing that at the moment is why the Total column isn't updating.
Btw, if I've understood what you are asking about that correctly, then your second point
I know how to calculate field but don't know how to multiplication(*) all field after (+)
is a different technical point which needs to be in a separate, new question, and you'll need to explain a bit more about what it is that you are having difficulty doing.