문제

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 := ??
도움이 되었습니까?

해결책 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;

다른 팁

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top