如何解决Crystal Reports 8.5 SetDataSource 生成空错误信息
我有一个使用 Crystal Reports 8.5 查看报表的 VB6 应用程序。我现在已经创建了一个使用 SQL Server 存储过程作为数据源的新报表。在我的应用程序中查看此报告时,我使用 ADODB.Recordset
作为报告的数据源。问题是 Crystal Reports 无法显示报告。它只显示一个空的数据库错误消息,以及一个“服务器尚未打开”的信息警告。
我用谷歌搜索我的生活取决于它,但我只找到了完全符合我正在做的事情的例子。有时会有一些细微的差别,但我都试过了。它们以相同的错误消息结束。
这是我填充记录集的代码。
Dim Records As ADODB.Recordset
Dim Cmd As ADODB.Command
Set Cmd = New ADODB.Command
Cmd.ActiveConnection = clSQL.DBConnection '< -- Existing connection that uses CursorLocation adUseClient
Cmd.CommandType = adCmdStoredProc
Cmd.CommandText = "SPCrystalReports"
Cmd.Parameters.Append Cmd.CreateParameter("ReportType",adVarChar,adParamInput,256,Soort)
Cmd.Parameters.Append Cmd.CreateParameter("ReportFile",RapportNaam)
Cmd.Parameters.Append Cmd.CreateParameter("Template",Template)
Cmd.Parameters.Append Cmd.CreateParameter("WhereClause",8000,CentralSQL)
Cmd.Parameters.Append Cmd.CreateParameter("WhereClause2",ExtraSQL)
Cmd.Parameters.Append Cmd.CreateParameter("Date",adDate,Datum)
Cmd.Parameters.Append Cmd.CreateParameter("DateFrom",DatumVan)
Cmd.Parameters.Append Cmd.CreateParameter("DateTo",DatumTot)
Set Records = Cmd.Execute
Set Cmd = Nothing
这是我加载报告的方式:
Dim crApp As CRAXDRT.Application
Dim crRep As CRAXDRT.Report
Set crApp = New CRAXDRT.Application
Set crRep = crApp.OpenReport(ReportFile,1)
然后我尝试了以下代码示例以使报告正常工作。
示例 1:
crRep.DiscardSavedData
crRep.Database.SetDataSource Records
示例 2:
crRep.DiscardSavedData
crRep.Database.SetDataSource Records,3,1
示例 3:
crRep.Database.Tables(1).SetLogOnInfo DBServer,DBDatabase,DBUser,DBPass
crRep.DiscardSavedData
crRep.Database.SetDataSource Records,1
示例 4:
crRep.DiscardSavedData
crRep.Database.Tables(1).SetDataSource Records,3
示例 5:
crRep.Database.Tables(1).SetLogOnInfo DBServer,DBPass
crRep.DiscardSavedData
crRep.Database.Tables(1).SetDataSource Records,3
示例 6:
crRep.DiscardSavedData
crRep.Database.Tables(1).SetPrivateData 3,Records
示例 7:
crRep.Database.Tables(1).SetLogOnInfo DBServer,DBPass
crRep.DiscardSavedData
crRep.Database.Tables(1).SetPrivateData 3,Records
他们都以这个错误弹出窗口和信息弹出窗口结束。
如何让它工作?
解决方法
如果没有执行错误并且 Records 变量包含数据,请尝试使用(对象浏览器不可见)方法 SetPrivateData:
crRep.Database.Tables(1).SetPrivateData 3,Records
Pdsoledb.dll (p2soledb.dll) as crRep.Database.Tables(1).DllName 表示您的报告应该自行从数据库中检索数据,因此请尝试以下操作:
With crRep.Database.Tables(1).ConnectionProperties
.DeleteAll
.Add "Connection String"," insert a connection string here "
End With
或者使用像这里的 LogOnServer 方法 VB and Crystal Reports problem
或将报告的连接类型更改为仅字段定义。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。