[SOLVED] SQLite Sum() lazarus / 16-Databases ---------------------------------------------------------------------- Pe3s · 2022-11-23 16:48 Hello, I have a question if it is possible to display the result of the summation in a control other than dbgrid? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button10Click(Sender: TObject);begin  ZQuery1.SQL.Clear;  ZQuery1.SQL.Text:= 'SELECT SUM(amount) FROM product';  ZQuery1.Open;end; ---------------------------------------------------------------------- Thaddy · 2022-11-23 17:39 In any text based control, like a memo or even a caption. (And plz do not use Zeos, use what Freepascal has a default. Zeos is a pain debugging and never has been fit for purpose) ---------------------------------------------------------------------- Pe3s · 2022-11-23 18:17 But when I execute this code it still displays in dbgrid ---------------------------------------------------------------------- Pe3s · 2022-11-23 19:21 What do I need to change in the code to make it add up the time? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button10Click(Sender: TObject);var  bm: TBookmark;  Total: Integer;begin  bm := ZQuery1.GetBookmark;  ZQuery1.DisableControls;  try    Total := 0;    ZQuery1.First;    while not ZQuery1.Eof do    begin      Total := Total + ZQuery1.FieldByName('Wiek').AsInteger;    ZQuery1.Next;    end;    Form1.Caption := IntToStr(Total);  finally  ZQuery1.GotoBookmark(bm);    ZQuery1.EnableControls;  end;end; ---------------------------------------------------------------------- paweld · 2022-11-23 20:09 This is probably because you are using a only one a TZQuery component in the application, which is connected to the grid via datasource. Place another ZQuery component on the form, such as ZQuery2Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button10Click(Sender: TObject);begin  ZQuery2.SQL.Clear;  ZQuery2.SQL.Text:= 'SELECT SUM(wiek) suma_lat FROM pracownik';  ZQuery2.Open;  try    Form1.Caption := ZQuery2.FieldByName('suma_lat').AsString;  finally    ZQuery2.Close;  end;end; ---------------------------------------------------------------------- dseligo · 2022-11-23 20:19 Quote from: paweld on November 23, 2022, 09:09:24 pmPlace another ZQuery component on the form, such as ZQuery2 And don't forget to connect it to ZConnection. Oh, and Zeos works just fine. ---------------------------------------------------------------------- Pe3s · 2022-11-24 15:28 Thank you