How to get SQL query results?

Using Delphi 2010, I used TSQLQuery and TSQLConnection to connect to a remote MySQL server. I used the SQL query as follows:

SQLQuery1.SQL.Text := 'SELECT * FROM registered WHERE email="'+email+'" and login_pass="'+password+'"';

SQLQuery1.Open; // Open sql connection

What should I do to display or display the data selected by this query?

When i type

SQLQuery1['who']; // The resault is : James Kan

I think it displays the last item in the list. But I want to display every element as I could with a foreach loop in PHP. How can I create, for example, a TLabel for each element?

+5
source share
1 answer

You just iterate over the result, for example

SQLQuery1.Open;
SQLQuery1.First; // move to the first record
while(not SQLQuery1.EOF)do begin
   // do something with the current record
   ...
   // move to the next record
   SQLQuery1.Next;
end;
+12
source

All Articles