简体   繁体   English

具有对象数据集的Crystal报表

[英]Crystal Report with Object Dataset

I was given a task of rewriting some Crystal Reports. 我的任务是重写一些Crystal Reports。 I found the original reports circa 1999, opened them up in VS 2008 made the changes and saved them. 我发现原始报告大约在1999年,在VS 2008中将其打开并进行了更改并保存。

Now, they reference a database that is no longer around. 现在,他们引用了一个不再存在的数据库。 So, I deleted this data source and added a .NET OBJECT datasource. 因此,我删除了此数据源并添加了.NET OBJECT数据源。 I changed everything around so that the fields now look at this new datasource. 我更改了周围的所有内容,以使字段现在可以查看这个新的数据源。

My intent was to create the report and during run time, pass it a datatable. 我的意图是创建报告,并在运行时将其传递给数据表。 This table is created by running a sproc created. 通过运行创建的存储过程来创建该表。

When I run it, I get the first page of the report. 运行它时,我将获得报告的第一页。 But when I try to change pages or print, I get an error: 但是,当我尝试更改页面或打印时,出现错误:

Logon failed. 登录失败。 Details: crdb_adoplus : Object reference not set to an instance of an object. 详细信息:crdb_adoplus:未将对象引用设置为对象的实例。 Error in File C:...\\MR01 {8E5164A9-4B01-4019-81E6-87AED65A02DF}.rpt: Unable to connect: incorrect log on parameters 文件C中的错误:... \\ MR01 {8E5164A9-4B01-4019-81E6-87AED65A02DF} .rpt:无法连接:错误的登录参数

Here is my code: 这是我的代码:

<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, JGauffin,

Like Lee, I am curious why you'd load a dataset with stored procedure data rather than just pass the credentials to the Crystal Report. 与Lee一样,我很好奇为什么您要使用存储过程数据加载数据集,而不是仅将凭据传递给Crystal Report。

In fact, the code you show doesn't even load a dataset directly anyways. 实际上,您显示的代码甚至都不会直接加载数据集。 I suggest you have the report pull data directly from the data server using your stored procedure. 我建议您使用存储过程直接从数据服务器中提取报表数据。 This just requires that you set credentials to access the server. 这只需要您设置凭据即可访问服务器。

If you remove all this code... 如果删除所有这些代码...

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

... you can reintroduce this convenience method: ...您可以重新引入此便捷方法:

// this line needs you to replace these arguments with the valid values
oReport.SetDatabaseLogon("your", "valid", "settings", "here");

Then, if you only see problems on paging, printing and exporting, you should make sure you keep setting the ReportSource back to the view. 然后,如果仅在分页,打印和导出方面看到问题,则应确保将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"];
}

I hope this gets you on the right path. 我希望这能使您走上正确的道路。

Try following the instructions here: http://vb.net-informations.com/crystal-report/vb.net_crystal_report_without_database.htm 尝试按照此处的说明进行操作: http : //vb.net-informations.com/crystal-report/vb.net_crystal_report_without_database.htm

I think you will need to get rid of this too: 我认为您也需要摆脱这种情况:

    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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM