我用database desktop建立了表,用dbgrid ,datasource ,query 三个控件 实现表的查询功能,但是当输入查询条件,查询时,总是提示invalid use of keyword  token:order linenumber:1  ,这是怎么回事?谢谢!!

解决方案 »

  1.   

    procedure Tmainfrm.butn_findClick(Sender: TObject);
    var
      SQLStr,SQLAll,Log:String;
      SQLTemp:Pchar;
      arrstr:array[1..4]of String;
      i,l:integer;
      function getsth(CurrEdit:TEdit):boolean;
      begin
        result:=false;
        if CurrEdit.Text<>'' then
          result:=true;
      end;
    begin
      SQLAll:='';
      SQLStr:='SELECT * FROM "E:\lgm\yun.db" WHERE ';
      //add(' where 字段 like '+QuotedStr('%'+trim(Edit1.text)+'%'));
      if RadioGroup1.ItemIndex=1 then Log:='OR' else Log:='AND';
      if Getsth(Edit_no) then
        arrstr[1]:='(编号='''+Edit_no.Text+''')';
      arrstr[3]:=edit_name.text;
      if arrstr[2]<>'' then
        arrstr[2]:='(书名='''+arrstr[2]+''')';
      if Getsth(Edit_pub) then
        arrstr[3]:='(出版社='''+Edit_pub.Text+''')';
        arrstr[4]:='';
      for i:=1 to 3 do
      begin
        arrstr[4]:=arrstr[4]+arrstr[i];
        if arrstr[i]<>'' then
          SQLAll:=SQLAll+Log+arrstr[i];
      end;
      if arrstr[4]='' then
      begin
        showmessage('没有查询项目?');
        exit;
      end;
      
      l:=strlen(Pchar(SQLAll));
      GetMem(SQLTemp,l);
      SQLTemp^ := Chr(0);  if SQLAll[1]='O' then
        StrCat(SQLTemp,Pchar(SQLAll)+2);
      if SQLAll[1]='A' then
        StrCat(SQLTemp,Pchar(SQLAll)+3);  SQLStr:=SQLStr+SQLTemp+' ORDER BY 编号,书名,出版社';
      FreeMem(SQLTemp);
    //  Application.MessageBox(Pchar(SQLStr),'预查询的SQL语句',MB_OK);  with Query1 do
      begin
        SQL.Clear;
        SQL.Add(SQLStr);
        Prepare;
        ExecSQL;
        Open;
      end;