[英]Crystal Report with Object Dataset
我的任务是重写一些Crystal Reports。 我发现原始报告大约在1999年,在VS 2008中将其打开并进行了更改并保存。
现在,他们引用了一个不再存在的数据库。 因此,我删除了此数据源并添加了.NET OBJECT数据源。 我更改了周围的所有内容,以使字段现在可以查看这个新的数据源。
我的意图是创建报告,并在运行时将其传递给数据表。 通过运行创建的存储过程来创建该表。
运行它时,我将获得报告的第一页。 但是,当我尝试更改页面或打印时,出现错误:
登录失败。 详细信息:crdb_adoplus:未将对象引用设置为对象的实例。 文件C中的错误:... \\ MR01 {8E5164A9-4B01-4019-81E6-87AED65A02DF} .rpt:无法连接:错误的登录参数
这是我的代码:
<CR:CrystalReportViewer ID="theCrystalReportViewer" visible="false" runat="server" EnableDatabaseLogonPrompt="false" />
Dim theDataTable As DataTable = tbl
theDataTable.TableName = "tableName"
Dim oReport As New ReportDocument
Dim sRptPath As String = "...Reports\MR01.rpt"
oReport.Load(sRptPath)
oReport.SetDataSource(theDataTable)
'oReport.SetDatabaseLogon("####", "####", "####", "#####")
Dim c As ConnectionInfo = New ConnectionInfo()
c.ServerName = "####"
c.DatabaseName = "####"
c.Password = "####"
c.UserID = "####"
c.Type = ConnectionInfoType.SQL
c.IntegratedSecurity = False
For i As Integer = 0 To theCrystalReportViewer.LogOnInfo.Count - 1
theCrystalReportViewer.LogOnInfo(i).ConnectionInfo = c
Next
'theCrystalReportViewer.EnableDatabaseLogonPrompt = False
'theCrystalReportViewer.DisplayGroupTree = False
theCrystalReportViewer.ReportSource = oReport
theCrystalReportViewer.DataBind()
litMsg.Visible = False
theCrystalReportViewer.Visible = True
JGauffin,
与Lee一样,我很好奇为什么您要使用存储过程数据加载数据集,而不是仅将凭据传递给Crystal Report。
实际上,您显示的代码甚至都不会直接加载数据集。 我建议您使用存储过程直接从数据服务器中提取报表数据。 这只需要您设置凭据即可访问服务器。
如果删除所有这些代码...
Dim c As ConnectionInfo = New ConnectionInfo()
c.ServerName = "####"
c.DatabaseName = "####"
c.Password = "####"
c.UserID = "####"
c.Type = ConnectionInfoType.SQL
c.IntegratedSecurity = False
For i As Integer = 0 To theCrystalReportViewer.LogOnInfo.Count - 1
theCrystalReportViewer.LogOnInfo(i).ConnectionInfo = c
Next
...您可以重新引入此便捷方法:
// this line needs you to replace these arguments with the valid values
oReport.SetDatabaseLogon("your", "valid", "settings", "here");
然后,如果仅在分页,打印和导出方面看到问题,则应确保将ReportSource设置回该视图。
if (!IsPostBack)
{
// all your existing code should go in here
// this includes the SetDatabaseLogon etc.
// at the right moment, save your oReport in session
Session["myReportDocument"] = oReport;
theCrystalReportViewer.ReportSource = oReport;
}
else // we are posting back, so make sure the viewer still has the report object
{
theCrystalReportViewer.ReportSource = (ReportDocument)Session["myReportDocument"];
}
我希望这能使您走上正确的道路。
尝试按照此处的说明进行操作: http : //vb.net-informations.com/crystal-report/vb.net_crystal_report_without_database.htm
我认为您也需要摆脱这种情况:
Dim c As ConnectionInfo = New ConnectionInfo()
c.ServerName = "####"
c.DatabaseName = "####"
c.Password = "####"
c.UserID = "####"
c.Type = ConnectionInfoType.SQL
c.IntegratedSecurity = False
For i As Integer = 0 To theCrystalReportViewer.LogOnInfo.Count - 1
theCrystalReportViewer.LogOnInfo(i).ConnectionInfo = c
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.