簡體   English   中英

具有對象數據集的Crystal報表

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM