先贴出代码吧:
procedure TFrmMain.Button2Click(Sender: TObject);
begin
 if cxTextEdit1.text='' then exit ;
  if not idftp1.Connected then idftp1.Connect;
  adoquery1.Connection:=adoconnection1;
   ADOQuery1.Close;
   ADOQuery1.Open;
     showmessage(ADOQuery1.SQL.Text);
  ADOQuery1.SQL.Text:='select filename from test where shno='''+
    cxTextEdit1.text+'''';  Label1.caption:=adoquery1.FieldByName('filename').AsString ;
end;
我的目的是先实现通过cxTextEdit1.text输入一个单号,查出匹配的数据再输到一个lable上
但是这样写总是报错:“无效的授权说明”
请高手解答一下或者给其它的源代码也行!!谢谢

解决方案 »

  1.   


    procedure TFrmMain.Button2Click(Sender: TObject);
    begin
      if cxTextEdit1.text='' then exit ;
      if not idftp1.Connected then idftp1.Connect;
      if ADOConnection1.Connected then begin
        adoquery1.Connection:=adoconnection1;
        ADOQuery1.Close;
        ADOQuery1.SQL.Text := 'select filename from test where shno= '+QuotedStr(cxTextEdit1.text);
        showmessage(ADOQuery1.SQL.Text);
        ADOQuery1.Open;
        Label1.caption:=adoquery1.FieldByName('filename').AsString ;
      end
      else showmessage('ADOConnection1未连接。');
    end;
      

  2.   

    为什么总是说ADOConnection1未连接
      

  3.   

    gzzai 能给我解释一下,为什么我那样写就错了呢!!非常感谢
      

  4.   

    ADOQuery1.SQL.Text 不能在 open 后才赋值。
      

  5.   

    其实,是用不着“ if ADOConnection1.Connected then ”条件成立才可以 ADOQuery1.Open; 的,因为激活 ADOQuery1 时,只要 ADOConnection1 的连接串设置正确,系统就会同时激活 ADOConnection1 的了。那为什么我又那样判断呢?因为我不明白你这个语句“ if not idftp1.Connected then idftp1.Connect; ”所判断的组件 “idftp1”,是不是跟“ADOConnection1”实际是同一个东西,仅是打错了名称否。故此,加个判断“if ADOConnection1.Connected then”,当条件成立时,下面的语句则能激活 ADOQuery1 了,不成立,你自然也会找原因。果然,你很聪明,很快就知道了:“不用了 我知道问题所在了。谢谢!”。