I Tried to get result from ADOQuery in Delphi. I wrote this function for Get a Name from table according custom ID.
function GetNameByID(Id : Integer) : string;
var query : string;
Begin
ShowMessage(GetDBGridViewIndex().ToString);
query := 'SELECT Name FROM Table1 WHERE ID=' + IntToStr(Id);
With ADOQuery do
Begin
try
SQL.Clear;
SQL.Add(query);
Open;
First;
Result:= // Need Get Result;
finally
Close;
end;
End;
ShowMessage(result);
End;
But I don't know how can return Result from ADOQuery.
TADOQueryis a descendant ofTDataset. You can iterate through the result records with the First, Next, Prior, and Last methods and find out if you've reached the end with Eof.Within each result record you can access the fields with:
or
In this case you can access to the result using:
After you
Openthe query, the cursor is pointing the First record. You don't need to call theFirstmethod afterOpen.