请问delphi中的Tquery控件如何实现以下功能?(50分)

  • 主题发起人 主题发起人 xeoniv
  • 开始时间 开始时间
X

xeoniv

Unregistered / Unconfirmed
GUEST, unregistred user!
在delphi中使用tquery控件首先用select查询到符合条件的记录,将字段的值作为我程序中
另一个函数的参数,应该怎么做?
也就是说:
procedure Form1.execute(Sender:TObject);
var
value:integer;
begin
/*这里写下查询的语句,并赋值给value;
OtherFunction(Value);//OtherFunction是我另外写的一个函数
end;
请大家多多帮忙,谢谢了。
 
procedure Form1.execute(Sender:TObject);
var
value:integer;
begin
value:=query.FieldByName('字段名').AsInteger;
OtherFunction(Value);//OtherFunction是我另外写的一个函数
end
 
procedure Form1.execute(Sender:TObject);
var
value:integer;
begin
with query do
begin
close;
sql.clear;
sql.add('select * from 你的表名');
sql.add('where 符合条件的字段名=你的条件');
open;
end;
value:=query.FieldByName('字段名').AsInteger;
OtherFunction(Value);//OtherFunction是我另外写的一个函数
end
 
不是吧大哥。query如何fieldbyname?而且我还没有查询呢?连表都没有找到如何等呢?
请大哥您再说详细一点,多谢了,分不够可以商量。
 
就是PARAMR
 
你不是不会在Query用查询吧
Query.Add('Select 你要在字段 from 你的表 where 字段=:条件字串');
ParamByName('条件字串').Value:=你的条件;
Query.open;

i:=Query.FileldByName('你的字段').AsInterger;
OtherFunction(i);//OtherFunction是我另外写的一个函数

如果查到多个的话就要用个循环
Query.First;
where (not (Query.eof)) do
begin
Query.next;
i:=Query.FileldByName('你的字段').AsInterger;
OtherFunction(i);//OtherFunction是我另外写的一个函数

end;


 
谢谢,已接受答案

 
题外话,大哥们,为什么我用sql.execsql不行,一定要用sql.open呢?
虽然没分了,还请大家帮助小弟,不胜感谢
 
后退
顶部