Retrieve multi-result set with ADO (Delphi)

来源:互联网 发布:淘宝刷钻是真的吗 编辑:程序博客网 时间:2024/06/05 09:41
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids, FMTBcd, DBXpress,
  DBClient, ComObj;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  AQry: TADOQuery;
  ADS: TCustomADODataSet;
  RowAffected, Seq: Integer;
begin
  AQry := TADOQuery.Create(Self);
  ADS := TCustomADODataSet.Create(Self);
  AQry.ConnectionString :=
    'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=.';
  AQry.SQL.Text := 'select * from jobs' + #13#10 + ' select * from employee';

  Seq := 1;

  try
    AQry.Open;
    ADS.Recordset := AQry.Recordset;

    while ADS.Recordset <> nil do
    begin
      TfrmData.CreateDataForm(Self, ADS.Recordset, Seq).Show;
      Inc(Seq);
      ADS.Recordset := AQry.NextRecordSet(RowAffected);
    end;
  finally
    FreeAndNil(AQry);
    FreeAndNil(ADS);   
  end;

  Button1.Enabled := false;
end;

end.