我一直在尝试使用以下Visual Basic代码浏览基于SQL Server数据库的Crystal Reports版本8:
CrystalReport1.ReportFileName = "C:\Report1.rpt"
CrystalReport1.Destination = crptToWindow
CrystalReport1.DiscardSavedData = True
CrystalReport1.WindowState = crptMaximized
MsgBox "Ok!", vbInformation
CrystalReport1.Action = 1
我正在使用Crystal Reports控件。该报告的数据库是连接到SQL Server的ODBC datasource
。没有DiscardSavedData
这可行,但它显示旧数据。使用DiscardSavedData
,我收到错误消息:
- 错误20599无法打开SQL Server。
我该如何解决这个问题?
我通过添加连接字符串CrystalReport1.Connect
解决了我的问题,我想分享我的解决方案。
CrystalReport1.ReportFileName = "C:\Report1.rpt"
CrystalReport1.Destination = crptToWindow
CrystalReport1.DiscardSavedData = True
CrystalReport1.Connect ="Data Source=Localhost;UID=sa;PWD=****;DSQ=Dat BdName;"
CrystalReport1.WindowState = crptMaximized
CrystalReport1.Action = 1