Cannot pass parameter to crystal report RRS feed

  • Question

  • User-2128752353 posted

     I am using the following code to pass parameter from VB to crystal report but getting the error messgae "Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))" while it trying to add the first parameter.  This chunk of coding works in another VB perfectly.  The only diffferent is the working one takes the parameter to stored procedure where the failed one I added parameter during crystal report design time.  Anyone has a clue?

     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim VirtualPath As String = Request.ApplicationPath.Substring(1, Request.ApplicationPath.Length - 1)
            Dim StmtFOlder As String = Server.MapPath("~/") & VirtualPath & "stmt"
            If Not System.IO.Directory.Exists(StmtFOlder) Then
            End If
            Dim Crystal As New CrystalReport
            Crystal.RptPath = Server.MapPath("~/CRDftn/") + "CrystalReport.rpt"
            Crystal.PathPDF = StmtFOlder & "/test.pdf"
            Crystal.CreatePDF = True
            Crystal.PrintReport = False
        End Sub


    Monday, June 21, 2010 12:19 AM

All replies

  • User-1900356179 posted


    It seems you're supplying one or more parameters extra to the reports which a report is not expecting. If this is not the case then try the work around mentioned below..


    It seems that line is expecting a parameter index and not the specific name of the parameter.

    rptReport.SetParameterValue(0, obj);
    rptReport.SetParameterValue(1, obj);
    rptReport.SetParameterValue(2, obj);

    Set report object = to the actual report and not loading the report. If you load the report rather then set it equal to the actual report, it might not know the parameter names.

    <!-- / message -->
    Monday, June 21, 2010 12:53 AM
  • User-2128752353 posted

    Thanks,  Rahul.

    Would you mind to show me how my code should be corrected?

    Monday, June 21, 2010 1:03 AM
  • User-1802908944 posted

    you can try this

                    irptDocument.SetParameterValue("SessionDate", Session["SessionDate"]);
                    irptDocument.SetParameterValue("ExaminationName", Session["ExaminationName"]);
                    irptDocument.SetParameterValue("UserName", Session["UserName"]);
                    crvViwer.DisplayGroupTree = false;
                    crvViwer.ReportSource = irptDocument;

    this is working code.

    happy coding

    Monday, June 21, 2010 1:10 AM
  • User-2128752353 posted

    Sorry, where does the dsTranScript come from? 

    Monday, June 21, 2010 1:18 AM
  • User-2128752353 posted

    Actually my posted code works too if the data source is a stored procedure with input parameter.  But this time instead I change to two tables. 

    Monday, June 21, 2010 1:20 AM