我目前在VB.Net(VS2010)应用程序中显示Crystal Report时遇到问题。我用Google搜索了这个问题,发现了类似的问题,但是他们的解决方案没有修复我的问题。
每次我从VB应用程序调用CR报告时,它总是会提示数据库登录。我输入了我的数据库凭据但它失败了。我通过ODBC连接器连接到MySQL5.1。
在我的Crystal Report中,我创建了一个自定义命令,它接受来自我的应用程序的两个参数,e.i,dateFrom和dateTo,我用它来查询日期范围。
我注意到当我取消设置Crystal Report参数值的代码时,数据库登录不会出现。
这是我的代码段:
Dim appPath As String = Path.GetDirectoryName(Application.ExecutablePath)
Dim cryRpt As New ReportDocument
Dim CRTable As CrystalDecisions.CrystalReports.Engine.Table
Dim CRTLI As CrystalDecisions.Shared.TableLogOnInfo
cryRpt.Load(appPath & "\Reports\crDtrLogs.rpt")
frmReportViewer.crReportViewer.Refresh()
For Each CRTable In cryRpt.Database.Tables
CRTLI = CRTable.LogOnInfo
With CRTLI.ConnectionInfo
.ServerName = "dtrsql"
.UserID = "root"
.Password = "root"
.DatabaseName = "dtrsql"
End With
CRTable.ApplyLogOnInfo(CRTLI)
Next CRTable
当我把它拿出来时,即使没有添加表格连接信息,一切也能正常工作
cryRpt.SetParameterValue("dtpFrom", dtpFrom.Value.Date.ToString("yyyy-MM-dd"))
cryRpt.SetParameterValue("dtpTo", dtpTo.Value.Date.ToString("yyyy-MM-dd"))
cryRpt.SetParameterValue("strDateRange", dtpFrom.Value.Date.ToString("MMMM dd, yyyy") & " - " & dtpTo.Value.Date.ToString("MMMM dd, yyyy"))
frmReportViewer.crReportViewer.ReportSource = cryRpt
frmReportViewer.Show()
与往常一样,非常感谢任何帮助。
答案 0 :(得分:0)
数据源:。\ Databasename.accdb
和查看器表单上的代码加载为
Dim cryRpt As New ReportDocument
Dim Report1 As New rptItemWise
Dim strServerName As String
strServerName = Application.StartupPath
rptItemWise.SetDatabaseLogon(" admin","",strServerName," dastabasename.accdb",True)
cryRpt.Load(Application.StartupPath + "\rptItemWise.rpt")
也会更改与数据源相同的报表连接,我认为该代码适合您..
答案 1 :(得分:0)
检查此代码。我想你应该像这样访问数据库:
Dim appPath As String = Path.GetDirectoryName(Application.ExecutablePath)
Dim cryRpt As New ReportDocument
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim CrTables As Tables
cryRpt.Load(appPath & "\Reports\crDtrLogs.rpt")
crConnectionInfo.ServerName = "YOUR SERVER NAME"
crConnectionInfo.DatabaseName = "YOUR DATABASE NAME"
crConnectionInfo.UserID = "YOUR DATABASE USERNAME"
crConnectionInfo.Password = "YOUR DATABASE PASSWORD"
CrTables = cryRpt.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next CrTable