我的未来

我的未来

导航

Delphi在程序中“拼SQL语句”获取结果

Posted on 2012-04-07 12:29  MKing  阅读(256)  评论(0)    收藏  举报
var
   Qry:TAdoQuery;
   singleRecord,Response:string;
 begin
    Context.Response:='获取合约列表返回数据!';
    Qry:=TAdoQuery.Create(nil);
    try
      try
        Qry.Connection:=Context.Cn;
        Qry.Close;
        Qry.SQL.Clear;
        Qry.SQL.Add('select * from wmnow..code');
        Qry.Open;
        while not Qry.Eof do
        begin
          singleRecord:=Qry.FieldByName('i_unit').AsString+';'+Qry.FieldByName('v_unit').AsString+';'
                             +Qry.FieldByName('i_dot').AsString;
          Response:=Response+singleRecord+'|';
          Qry.Next;
        end;
        SetLength(Response,Length(Response)-1);
      except
        on   E:Exception   do
        begin
           MainForm.MemoPrint('数据库连接失败,请检查连接');
        end;
      end
    finally
       Qry.Free;
    end;
    Context.Response:=Response;
 end;