locked
How to passing dynamic parameter to subreport with stored procedure sql? RRS feed

  • Question

  • User1668405342 posted

    Hello,

    i have some problem with subreport that i create. i want to passing dynamic parameter from textbox field to stored procedure sql and use the parameter to show data to my subreport like my main report. 

    This is my code for main report :

    Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
            ConfigureReport()
        End Sub
    
        Private Sub ConfigureReport()
            Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
            myConnectionInfo.DatabaseName = "db1"
            myConnectionInfo.UserID = "user"
            myConnectionInfo.Password = "pass"
    
            Dim ReportPath As String = Server.MapPath("~/sample.rpt")
            CrystalReportViewer1.ReportSource = ReportPath
    
            Dim field1 As ParameterField = Me.CrystalReportViewer1.ParameterFieldInfo(0)
            Dim field2 As ParameterField = Me.CrystalReportViewer1.ParameterFieldInfo(1)
            Dim field3 As ParameterField = Me.CrystalReportViewer1.ParameterFieldInfo(2)
    
            Dim val1 As New ParameterDiscreteValue()
            Dim val2 As New ParameterDiscreteValue()
            Dim val3 As New ParameterDiscreteValue()
    
            val1.Value = txtLease.Text
            val2.Value = txtBranchCode.Text
            val3.Value = txtUser.Text
    
            field1.CurrentValues.Add(val1)
            field2.CurrentValues.Add(val2)
            field3.CurrentValues.Add(val3)
    
            SetDBLogonForReport(myConnectionInfo)
        End Sub
    
        Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo)
            Dim myTableLogOnInfos As TableLogOnInfos = CrystalReportViewer1.LogOnInfo()
            For Each myTableLogOnInfo As TableLogOnInfo In myTableLogOnInfos
                myTableLogOnInfo.ConnectionInfo = myConnectionInfo
            Next
        End Sub
    

    but i don't know how the way passing that parameter to my subreport. can anyone help me?? 

    Thanks for advance.

    Best Regards,

    Younikorne.

    Thursday, December 20, 2012 2:32 AM

All replies

  • User-929656654 posted

    1) Create some parameter fields in main report itself (For Ex: subPar1, subPar2)
    2) Pass those parameter values from your C# (subPar1, subPar2). Hope it will be easy as they are in main report itself
    3) Now from Main report, pass the values of  subPar1, subPar2 parameter fields to sub report as parameters.

    Thursday, December 20, 2012 3:40 AM
  • User1668405342 posted

    Hello Sirama, 

    Can you explain with some example code. but otherways, i use vb.net not c#. hehe... 

    thanks before..

    Thursday, December 20, 2012 3:52 AM