Forum > Databases

[SOLVED] SQLite Sum()

(1/2) > >>

Pe3s:
Hello, I have a question if it is possible to display the result of the summation in a control other than dbgrid?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button10Click(Sender: TObject);begin  ZQuery1.SQL.Clear;  ZQuery1.SQL.Text:= 'SELECT SUM(amount) FROM product';  ZQuery1.Open;end;  

Thaddy:
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:
But when I execute this code it still displays in dbgrid

Pe3s:
What do I need to change in the code to make it add up the time?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
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 ZQuery2
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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;        

Navigation

[0] Message Index

[#] Next page

Go to full version