带对象数据集的Crystal Report

时间:2012-04-03 17:10:20

标签: asp.net .net vb.net crystal-reports

我被赋予了重写一些Crystal Reports的任务。我发现大约1999年的原始报告,在VS 2008中打开它们进行了更改并保存了它们。

现在,他们引用了一个不再存在的数据库。因此,我删除了此数据源并添加了一个.NET OBJECT数据源。我改变了一切,以便现在看到这个新的数据源。

我的目的是创建报告,在运行时,传递一个数据表。该表是通过运行创建的sproc来创建的。

当我运行它时,我会收到报告的第一页。但是当我尝试更改页面或打印时,出现错误:

  

登录失败。详细信息: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

2 个答案:

答案 0 :(得分:0)

请尝试按照此处的说明操作: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

答案 1 :(得分:0)

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"];
}

我希望这能让你走上正确的道路。