现在有表(table) 如下:id name ph demo
01 A 12 ZH
02 B 14 AC
03 C 16 DK
我现在想实现的功能是:通过我自己定义的一个widestring.进行和数据库的同步..
const
callerid:widestring;
begin
with adoquery1 do
begin
close;
sql.clear(select id from table where id=callerid);
下面的代码不知道写.因为数据库字段ID的值=callerid也等于edit1.text;
如果callerid=01 时,DBGrid显示的内容就是id=01的内容.并且在edit上也要显示
如果callerid=02时,DBGrid显示的内容就是id=02的内容.并且在edit上也要显示我现在提取的值都是数据表的第一条数据. 不能提第二条数据.我就想通过callerid的值来提取数据库的内容.
麻烦大家帮帮. 不知道我表达明白没有..
01 A 12 ZH
02 B 14 AC
03 C 16 DK
我现在想实现的功能是:通过我自己定义的一个widestring.进行和数据库的同步..
const
callerid:widestring;
begin
with adoquery1 do
begin
close;
sql.clear(select id from table where id=callerid);
下面的代码不知道写.因为数据库字段ID的值=callerid也等于edit1.text;
如果callerid=01 时,DBGrid显示的内容就是id=01的内容.并且在edit上也要显示
如果callerid=02时,DBGrid显示的内容就是id=02的内容.并且在edit上也要显示我现在提取的值都是数据表的第一条数据. 不能提第二条数据.我就想通过callerid的值来提取数据库的内容.
麻烦大家帮帮. 不知道我表达明白没有..
其实你就是想传递一个参数,然后执行sql语句显示某行数据,而这个参数你始终没有传递过去,显示的总是第一条记录
所以你应该传递的是一个变量,而不是常量
var
callidid:widestring;
begin
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select * from table where id=:callerid');
parameters.Items[0].Value:=callerid;
open;
end
edit1.Text:=adoquery1.fieldbyname('id').AsString;
//在edit1上显示更多内容,就把各个字段都加上去...
//edit1.Text:=adoquery1.fieldbyname('id').AsString+' '+adoquery1.fieldbyname('name').AsString;
end;不知道我这样描述是不是和你要实现的目的一致?