我试图从VB.Net代码调用水晶报告;调用CrystalReportViewer1.ReportSource = rptDoc语句报表查看器后出现;但是,登录凭据对话框显示在报告查看器上,要求提供凭据 . 我正在尝试使用dsn进行连接;以下是打印时调用的代码 .
Private Sub PrintReport()试试
Dim connInfo As New ConnectionInfo
Dim rptDoc As New ReportDocument
' load the Crystal Report
rptDoc.Load("D:\Xtrade\DMSAccounts_Notifications\DMSAccounts_Notifications\rptProductsExpiry.rpt")
' add required parameters
rptDoc.SetParameterValue("_whereclause", " registeration_Status=1")
Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
With crConnectionInfo
.ServerName = "expiry"
.DatabaseName = "" 'Np need to mention for dsn
.UserID = "xtrade"
.Password = "XTradeMySQL"
End With
CrTables = rptDoc.Database.Tables
'Loop through each table in the report and apply the LogonInfo information
For Each CrTable In rptDoc.Database.Tables
Dim repTblLogonInfo As TableLogOnInfo = CrTable.LogOnInfo
repTblLogonInfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(repTblLogonInfo)
Next
CrystalReportViewer1.ReportSource = rptDoc
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
这里有任何机构指出这段代码有什么问题 . 谢谢