DBGrid上面有ADOTable、ADOQuery,DataSource的dataset是ADOTable;向数据库中添加数据用的是ADOTable;然后查询的时候用ADOTable不好用,所以改用ADOQuery进行查询,但是查询的结果集怎么显示在DBGrid中呢?
//-------------------------------------------------------------------------------------------------
Form1.ADOQuery1.Close;
Form1.ADOQuery1.SQL.Clear;
Form1.ADOQuery1.SQL.Text:='select userID from userInfo where userID=:id and userName=:name';
Form1.ADOQuery1.Parameters.ParamByName('id').Value:=strtoint(Edit1.Text);
Form1.ADOQuery1.Parameters.ParamByName('name').Value:=trim(Edit2.Text);
Form1.ADOQuery1.ExecSQL;
Form1.ADOQuery1.Open;
if form1.ADOQuery1.RecordCount<>0 then
begin
close;
id:=Form1.ADOQuery1.FieldByName('userID').Value;
with Form1.ADOQuery1 do
begin
close;
SQL.Clear;
SQL.Add('select * from userInfo where userID=:id');
ExecSQL;
open;
Active:=true;
end;
form1.ADOTable1.Recordset:=form1.ADOQuery1.Recordset;
Form1.ADOTable1.Open;
end;
//-----------------------------------------------------------------------------------------
本来想将ADOQurey查询的结果集赋值给ADOTable,但是这样显示出来是空结果-_-|||
//-------------------------------------------------------------------------------------------------
Form1.ADOQuery1.Close;
Form1.ADOQuery1.SQL.Clear;
Form1.ADOQuery1.SQL.Text:='select userID from userInfo where userID=:id and userName=:name';
Form1.ADOQuery1.Parameters.ParamByName('id').Value:=strtoint(Edit1.Text);
Form1.ADOQuery1.Parameters.ParamByName('name').Value:=trim(Edit2.Text);
Form1.ADOQuery1.ExecSQL;
Form1.ADOQuery1.Open;
if form1.ADOQuery1.RecordCount<>0 then
begin
close;
id:=Form1.ADOQuery1.FieldByName('userID').Value;
with Form1.ADOQuery1 do
begin
close;
SQL.Clear;
SQL.Add('select * from userInfo where userID=:id');
ExecSQL;
open;
Active:=true;
end;
form1.ADOTable1.Recordset:=form1.ADOQuery1.Recordset;
Form1.ADOTable1.Open;
end;
//-----------------------------------------------------------------------------------------
本来想将ADOQurey查询的结果集赋值给ADOTable,但是这样显示出来是空结果-_-|||
解决方案 »
- delphi与C#
- 更改自定义组件的注册面板不生效 RegisterComponents
- 取外网ip地址,通过路由器上的网
- 请问下Pascal语言中二维数组A[3,4],是3表示行数还是4表示行数
- 如何解除数据库的锁定,请教前辈
- 高兴,放分
- 求 SQL语句,50分。要是分不足,可再加50.
- 关于MENU,COMBOBOX的简单问题。
- 用datetostr(DateTimePicker1.Date),插进access数据库后怎么变成1905-5-21了!
- 有没有快速的从BMP生成JPEG文件的函数
- 最近fastreport怎么没有更新了?以前更新很频繁啊
- 用vfw 写视频会议 ,但是画图 画不出来
SQL.Add('select * from userInfo where userID=:id');
应该改写如下
SQL.Add('select * from userInfo where id='+trim(userID)+')';