How to get results of a TQuery en Delphi?
DataBase
When I run the following query in a database:
SELECT T.ID FROM TABLA T WHERE ID=3
Resutl:
No rows returned
Now I try show message in Delphi say "The record not exist".
In the form I have a component TQuery call qValidacion successfully connected with database Oracle 11g.
Try 1
procedure TfPrueba.ButtonAceptarClick(Sender: TObject);
begin
qValidacion.Close;
qValidacion.SQL.Add('SELECT T.ID');
qValidacion.SQL.Add('FROM TABLA T');
qValidacion.SQL.Add('WHERE ID=3');
qValidacion.Open;
qValidacion.First;
if (not qValidacion.Eof) then
begin
ShowMessage('The record not exist'); //It Should display the message, but does not show
end;
qValidacion.SQL.Clear;
end;
If you want to check if they are any record in your Query don't use the qValidacion.EOF but qValidacion.IsEmpty
if (qValidacion.IsEmpty) then
begin
ShowMessage('The record not exist');
end;
The EOF Function is here for returning true when you reach the end of a DataSet. Example:
qValidacion.First;
while not qValidacion.eof do
begin
// do Something with the current record.
qValidacion.next
end;
Edit1: Using IsEmpty is indeed more clean. Thanks to Arioch 'The
链接地址: http://www.djcxy.com/p/35088.html上一篇: WebBrowser未分配
下一篇: 如何获得Delphi的TQuery结果?
