Delphi在程序中“拼SQL语句”获取结果
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;