日期:2014-05-20  浏览次数:20735 次

水晶报表中改变数据源问题,为什么用COMMAND对象调用存储过程查出来的记录集不能使用?
代码出下:  
Private   Sub   Form_Load()
Screen.MousePointer   =   vbHourglass
Dim   RS11   As   New   ADODB.Recordset
Dim   RS12   As   New   ADODB.Recordset
Dim   RS13   As   New   ADODB.Recordset

'---------------------------
'用自定义的COM组件中的函数返回查找出的记录集,实际是在函数中使用COMMAND对象调用存储过程,然后返回一个离线记录集。
Dim   o   As   Object
Set   o   =   CreateObject( "coGMDept.ioDepartments ")
Set   RS11   =   o.Departments()
'   o.Departments是一个自定义COM组件里的函数,返回一个记录集  
'----------------------------

'****************************************************************
'使用COMMAND对象调用存储过程,返回一个记录集。
Dim   conn   As   New   ADODB.Connection
Dim   connstr   As   String
"Provider=SQLOLEDB.1;Initial   Catalog=GEIMS;Data   Source=c-11;Persist   Security   Info=False;Integrated   Security=SSPI; "
conn.Open   connstr

Dim   Cmd   As   ADODB.Command
       
        Set   Cmd   =   New   ADODB.Command
       
        'Command   对象处理----------------------------------------
        With   Cmd
                .CommandType   =   adCmdStoredProc
                .CommandTimeout   =   30
                .CommandText   =   "SP_DEPARTMENTS_GET "
       
                .Parameters.Append   .CreateParameter( "@ID ",   adBigInt,   adParamInput,   ,   Null)
                .Parameters.Append   .CreateParameter( "@RETURNS ",   adBigInt,   adParamOutput)  

                .ActiveConnection   =   conn
               
                Set   RS12   =   .Execute
               
        End   With
'*****************************************************************
'#################################################################
'直接OPEN一个记录集。
        RS13.Open   "Select   *   from   DEPARTMENTS ",   conn,   3,   1
'#################################################################
'使用上述三种方法都能得到记录集,且内容一致  

'下面改变水晶报表的数据源
'Report.Database.SetDataSource   RS11
'Report.Database.SetDataSource   RS12
Report.Database.SetDataSource   RS13

'但只能使用第三种方法报表才可以正常显示,前面两种方式报表都是空的,但   debug.print   记录集RS11,RS12,RS13里面的记录,数据都完全是一样的   ,为什么?

Report.ReadRecords

CRViewer91.ReportSource   =   Report
CRViewer91.ViewReport
Screen.MousePointer   =   vbDefault

End   Sub

郁闷了几天了,那位大侠有经验,请传授一下,感激不尽。

------解决方案--------------------
up