将Crystal Report名称作为参数传递

时间:2010-12-03 10:08:13

标签: vb.net visual-studio-2008 crystal-reports

我正在使用一个调用水晶报告的函数:

ShowReport(Report1)

在节目报告中显示ShowReport:

Dim repDoc As New Report1  **' here i am want to assign crytalReport name**
repDoc.SetDatabaseLogon("username", "*****")
CrystalReportViewer1.ReportSource = repDoc
CrystalReportViewer1.Visible = True

我该怎么做?

1 个答案:

答案 0 :(得分:1)

我过去曾做过类似的事情,你可以将它用于你的目的。 Normaly我使用下拉列表或列表框来允许用户选择他们想要查看的文件,然后使用项目索引传递给intFileId。

Private Sub OpenCR(ByVal intfileId As Integer)
    Dim aReport As ReportDocument
    Select Case intfileId
        Case 0 : aReport = New CountSheets
        Case 1 : aReport = New CategoryVariance
        Case 2 : aReport = New DollarVariance
        Case 3 : aReport = New CategoryVarianceAdmin
        Case 4 : aReport = New DollarVarianceAdmin
        Case 5 : aReport = New PhysicalCount
        Case 6 : aReport = New BookToPhysicalCount
        Case 7 : aReport = New MissingItemCodes
    End Select

    aReport.Refresh()
    aReport.SetParameterValue("isAmtsShown", isAmtsShown)
    aReport.SetParameterValue("parStoreID", StoreID)
    aReport.SetDatabaseLogon("username", "password", "server", "table")
    crvReports.ReportSource = aReport

End Sub

回答有关传递名称作为参数的具体问题。你可以这样做:

 Private Sub RunReportbyName()
    ' The Crystal Report name in
    ' this project is MyReport.rpt
    Dim aReport As ReportDocument = New MyReport
    OpenCR(aReport)
End Sub

Private Sub OpenCR(ByVal RepDoc As ReportDocument)
    'RepDoc.SetDatabaseLogon("","","","")
    CrystalReportViewer1.ReportSource = RepDoc
    CrystalReportViewer1.Visible = True

End Sub