Domanda

I have an sqlite database and i want to execute a select query and show the result in the TEdit. How can i do it?

 query := 'SELECT username FROM users';  //The query returns only one row
 FDQuery1.ExecSQL;
 FDQuery1.Open();
 Edit1.Text := ??
È stato utile?

Soluzione 2

In your case, because you only have 1 column I would use:

Edit1.Text := FDQuery1.Fields[0].AsString;

But if you have mulitple column you select I would use:

Edit1.Text := FDQuery1.fieldbyname(<ColumnName>).AsString;

Altri suggerimenti

Edit1.Text := FDQuery1.Fields[0].AsString;

Please note that ExecSQL executes an SQL statement that does not return data, while Open executes a SELECT query. So you are executing the query twice.

ExecSQL haven't return value

Examp:

 FDQuery1.sql.add:= 'SELECT username FROM users';
 FDQuery1.Open();

 Edit1.Text := FieldByName('username').AsString;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top