码迷,mamicode.com
首页 > 其他好文 > 详细

Ado控件处理多个Recordset数据集

时间:2015-02-27 18:55:28      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:开发   procedure   ado   

在开发过程运用中,有时候一个ADO控件返回了多个数据集,例如存储过程返回了2个查询结果,如下面处理


------------------PAS文件--------------------------------------

procedure TForm1.Button1Click(Sender: TObject);
var
  recval: _Recordset;
  RecordsAffected: OleVariant;
  iRecordsAffected: Integer;
begin
  with ADOQueryComm do
  begin
    Close;
    SQL.Add(‘SELECT TOP 100 * FROM dbo.fnArtMain ‘);
    SQL.Add(‘SELECT TOP 100 * FROM dbo.fnArtDetail ‘);
    Open;
  end;

//  ADOQuery1.Recordset := ADOQueryComm.Recordset;

//  recval := ADOQueryComm.Recordset;
//  ADOQuery2.Recordset := recval.NextRecordset(RecordsAffected);

  ADOQuery2.Recordset := ADOQueryComm.NextRecordset(iRecordsAffected);
end;


-------------------DFM文件---------------------

object Form1: TForm1
  Left = 203
  Top = 150
  Width = 928
  Height = 480
  Caption = ‘Form1‘
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = ‘MS Sans Serif‘
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 912
    Height = 57
    Align = alTop
    Caption = ‘Panel1‘
    TabOrder = 0
    object Button1: TButton
      Left = 104
      Top = 8
      Width = 161
      Height = 33
      Caption = ‘打开数据集‘
      TabOrder = 0
      OnClick = Button1Click
    end
  end
  object Panel2: TPanel
    Left = 0
    Top = 57
    Width = 912
    Height = 192
    Align = alTop
    Caption = ‘Panel2‘
    TabOrder = 1
    object DBGrid1: TDBGrid
      Left = 1
      Top = 1
      Width = 910
      Height = 190
      Align = alClient
      DataSource = DataSource1
      TabOrder = 0
      TitleFont.Charset = DEFAULT_CHARSET
      TitleFont.Color = clWindowText
      TitleFont.Height = -11
      TitleFont.Name = ‘MS Sans Serif‘
      TitleFont.Style = []
    end
  end
  object Panel3: TPanel
    Left = 0
    Top = 249
    Width = 912
    Height = 193
    Align = alClient
    Caption = ‘Panel3‘
    TabOrder = 2
    object DBGrid2: TDBGrid
      Left = 1
      Top = 1
      Width = 910
      Height = 191
      Align = alClient
      DataSource = DataSource2
      TabOrder = 0
      TitleFont.Charset = DEFAULT_CHARSET
      TitleFont.Color = clWindowText
      TitleFont.Height = -11
      TitleFont.Name = ‘MS Sans Serif‘
      TitleFont.Style = []
    end
  end
  object ADOQuery1: TADOQuery
    Parameters = <>
    Left = 216
    Top = 72
  end
  object DataSource1: TDataSource
    DataSet = ADOQueryComm
    Left = 344
    Top = 80
  end
  object DataSource2: TDataSource
    DataSet = ADOQuery2
    Left = 448
    Top = 224
  end
  object ADOQuery2: TADOQuery
    Parameters = <>
    Left = 344
    Top = 224
  end
  object ADOQueryComm: TADOQuery
    ConnectionString =
      ‘Provider=SQLOLEDB.1;Password=test;Persist Security Info=True;U‘ +
      ‘ser ID=TEST;Initial Catalog=FinishingDB;Data Source=PC‘
    Parameters = <>
    Left = 208
    Top = 144
  end
end



本文出自 “畅想天空” 博客,请务必保留此出处http://kinwar.blog.51cto.com/3723399/1615626

Ado控件处理多个Recordset数据集

标签:开发   procedure   ado   

原文地址:http://kinwar.blog.51cto.com/3723399/1615626

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!