开发者

Passing Crystal Report name as parameter

I am using a function which is calling a crystal report as :

ShowReport ( Report1)

In show repo开发者_运维知识库rt ShowReport :

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

How can i do that ?


I have done something like this in the past that you may be able to use for your purposes. Normaly I use a Dropdown list or a Listbox to allow the user to select the file they want to view and then use pass the Item Index to the the 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

To answer the specific question about passing the name as the argument. You could do it with something like this:

 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜