[英]capture values from a simple select query TADOQuery Delphi
I am having issues returning the value gotten from a simple SELECT query using TADOQuery 我在使用TADOQuery返回从简单SELECT查询获得的值时遇到问题
here is my code below: 这是我的代码如下:
dbWizconQuery.SQL.Clear;
dbWizconQuery.SQL.Add('SELECT * FROM test');
tb_wizconValues.Items.Add('' + dbWizconQuery.SQL.GetText);
dbWizconQuery.ExecSQL;
processed := IntToStr(dbWizconQuery.FieldByName ('input' ).Value);
tb_wizconValues.Items.Add('' + processed);
I get the first print out in my textbox ok, with the SQL String but then i dont get the value coming out. 我用SQL字符串在我的文本框中确定了第一次打印,但是随后我没有得到值。
Can you see why this might be? 你知道为什么会这样吗?
Processed is a String and input is an INT(5) which comes out AsString 处理的是一个字符串,输入的是一个INT(5),它来自AsString
Kind Regards, 亲切的问候,
Jordan 约旦
ExecSQL
is used for statements that don't return a rowset, such as INSERT
, DELETE
and UPDATE
. ExecSQL
用于不返回行集的语句,例如INSERT
, DELETE
和UPDATE
。 For a SELECT
, you need to use Open
instead: 对于
SELECT
,您需要使用Open
代替:
dbWizconQuery.SQL.Clear;
dbWizconQuery.SQL.Add('SELECT * FROM test');
tb_wizconValues.Items.Add('' + dbWizconQuery.SQL.GetText);
dbWizconQuery.Open;
processed := IntToStr(dbWizconQuery.FieldByName ('input' ).Value);
tb_wizconValues.Items.Add('' + processed);
For more info, see the documentation for TDataSet 有关更多信息,请参见TDataSet的文档。
in delphi ExecSQL is used when you want to do an 在delphi中使用ExecSQL时,
UPDATE,INSERT,DELETE
when you want to do a select call open or just set the query to 当您想进行选择呼叫打开或只是将查询设置为
active := true;
you can get multiple results back by using this code: 您可以使用以下代码获得多个结果:
dbWizconQuery.SQL.Clear;
dbWizconQuery.SQL.Text := 'SELECT * FROM test';
dbWizconQuery.Open; // or dbWizconQuery.Active := True;
while not dbWizconQuery.eof do
begin
ShowMessage(dbWizconQuery.FieldByName('FieldName').AsString); // this shows the fields value
dbWizconQuery.Next; //use this line or you will get an infinite loop
end;
dbWizconQuery.Close; //closes the dataset
for executing statements like UPDATE,INSERT,DELETE use it like this: 对于执行UPDATE,INSERT,DELETE之类的语句,请像这样使用它:
dbWizconQuery.SQL.Text := 'DELETE FROM test WHERE ID = 1';
dbWizconQuery.ExecSQL;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.