开发者

Crystal Report Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))

I have made a crystal report in asp.net for web application. Some report open nicely. But sometimes it does not. It shows the following problem.

Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))

Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: [COMException (0x8002000b): Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))]

Report_Viewer.Page_Load(Object sender, EventArgs e) +894

System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14

System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35

System.Web.UI.Control.OnLoad(EventArgs e) +99

System.Web.UI.Control.LoadRecursive() +50

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAft开发者_JAVA技巧erAsyncPoint) +627

Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

My VS: VS 2008, Database:MS SQL Express 2005, OS:Windows 7

Is there any one to solve my problem..

NB: My code is in a Class

public ReportDocument ShowReport(string ReportName, string Parameter1)
{                              
    try
    {
        cryRpt.Load(ReportName);            
        cryRpt.SetDatabaseLogon(UserName, Password, ServerName, DatabaseName);                                    
        crParameterValues.Clear();
        crParameterDiscreteValue.Value = Parameter1;// as like Parameter1
        crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
        crParameterFieldDefinition = crParameterFieldDefinitions["@Parameter1"];
        crParameterValues = crParameterFieldDefinition.CurrentValues;
        crParameterValues.Add(crParameterDiscreteValue);
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
    }
    catch (Exception ex)
    {
       throw ex;
       //ShowReport(@"default_report.rpt");
    }
    //CleareParameter();
    return cryRpt;
}

Report Viewer Page load

protected void Page_Load(object sender, EventArgs e)
{
    string ReportName="";
    string Parameter1="";
    ReportName= Session["ReportName "].ToString();
    Parameter1 = Session["Parameter1"].ToString();
    }
    try
    {
        if (Session["Parameter2"].ToString() != null)
        {
            Parameter2 = Session["Parameter2"].ToString();
            icount = icount + 1;
        }
    }
    catch (Exception ) { }
    ReportViewer oReportViewer = new ReportViewer(); // Class file
    ReportDocument rptDoc = new ReportDocument();
    try
    {
        rptDoc = oReportViewer.ShowReport(ReportName, Parameter1);
        rptDoc = oReportViewer.ShowReport(ReportName, Parameter1, 
        rptDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "Report");
        CrystalReportViewer1.ReportSource = rptDoc;
    }
    catch (Exception ex)
    {  
       throw ex;
    }       
}


That is because the parameters (or parameters names) you set in your code are different from defined parameters in your report


crParameterFieldDefinitions["@Parameter1"];

Above line you will check that parameter exist or not. I think that one is not available.

Hope this one is helpful!!!


  1. Add One Method
Public Sub LoadReport()
    Try
        If Validation() = True Then Exit Sub

        If ClsDcon.ShowItems(Me.Text) = False Then Exit Sub
        Dim lvarr(4, 1) As String

        lvarr(0, 0) = "@CompId"
        lvarr(0, 1) = Connection.strGCompanyId  'strCompId

        lvarr(1, 0) = "@DepartmentId"
        lvarr(1, 1) = txtstaffAbscentees.GetTextBox.Tag      'strSDMUId

        lvarr(2, 0) = "@FromDate"
        lvarr(2, 1) = ClsDcon.ConvertDateToInt(dtpFromDate.GetTextBox.Text)                  'strFromDate

        lvarr(3, 0) = "@PFromDate"
        lvarr(3, 1) = "Staff Abscentees Report On: " & dtpFromDate.GetTextBox.Text 'ClsDcon.ConvertIntToDate(strFromDate)

        lvarr(4, 0) = "@Flags"
        lvarr(4, 1) = intFlag

        Me.Text = frmMain
        ClsDcon.LoadCrystalReport(New CrtStaffAbscentees, crpStaffAbscenteesReportviewer, lvarr)
    Catch ex As Exception

    End Try
End Sub

*2. Add Function To Load and Set Parameter*

Public Sub LoadCrystalReport(ByVal pvcrpReport As Object, ByVal pvcrvControl As CrystalReportViewer, Optional ByVal pvarrParamValues As Array = Nothing, Optional ByVal pvstrSelection As String = Nothing, Optional ByVal invVal As Integer = 0)
    Try

        Dim lvobjReport As Object = pvcrpReport
        'myRpt.Load("D:\Projects\MyAccountswin2008new\UILayer\Sales\Sales Reports\CrtPOSBillReport.rpt")

        For i As Integer = 0 To pvarrParamValues.GetUpperBound(0)
            lvobjReport.SetParameterValue(pvarrParamValues(i, 0).ToString, pvarrParamValues(i, 1))
        Next

        Dim lsMethod As String = System.Reflection.MethodBase.GetCurrentMethod().Name
        Dim loConnInfo As New CrystalDecisions.Shared.ConnectionInfo
        'Dim lsMode As String = Configuration.ConfigurationSettings.AppSettings("Mode")
        loConnInfo.ServerName = My.Settings.RPTServerName
        loConnInfo.DatabaseName = My.Settings.RPTDatabaseName
        loConnInfo.UserID = My.Settings.RPTUserID
        loConnInfo.Password = My.Settings.RPTPassword
        Dim loTables As CrystalDecisions.CrystalReports.Engine.Tables
        Dim loTable As CrystalDecisions.CrystalReports.Engine.Table
        Dim loTableLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
        loTables = lvobjReport.Database.Tables
        For Each loTable In loTables
            loTableLogonInfo = loTable.LogOnInfo
            loTableLogonInfo.ConnectionInfo = loConnInfo
            loTable.ApplyLogOnInfo(loTableLogonInfo)
            loTable.Location = loTable.Name
        Next
        'pvcrvControl.RefreshReport()
        pvcrvControl.ReportSource = lvobjReport
        pvcrvControl.Refresh()
        'pvcrvControl.RefreshReport()
        If invVal = 1 Then
            Dim prd As New System.Drawing.Printing.PrintDocument
            lvobjReport.PrintOptions.PrinterName = prd.PrinterSettings.PrinterName
            If lvobjReport.PrintOptions.PrinterName = "" Or lvobjReport.PrintOptions.PrinterName = Nothing Then
                MyMessagebox.MyMessagebox.ShowMessage("Set Default Printer", "Global Funtions_UI", MessageBoxIcon.Information)
            End If

            'prd.DefaultPageSettings.PaperSize.RawKind = PaperKind.Custom
            'prd.DefaultPageSettings.PaperSize.PaperName = "NewSize"
            'Dim prnPS As New Printing.PaperSize("HalfFolio", 850, 650)
            'Dim intIdx As Integer

            'For intIdx = 0 To prd.PrinterSettings.PaperSizes.Count - 1 Step 1
            '    If prd.PrinterSettings.PaperSizes(intIdx).Kind = Printing.PaperKind.Custom Then
            '        prnPS.RawKind = prd.PrinterSettings.PaperSizes(intIdx).RawKind
            '        prd.DefaultPageSettings.PaperSize = prnPS
            '    End If
            'Next
            'prd.Print()




            'If prd.DefaultPageSettings.PaperSize.Kind = PaperKind.Custom Then
            '    prd.DefaultPageSettings.PaperSize.Width = 827
            '    prd.DefaultPageSettings.PaperSize.Height = 650
            NumberofPrints()
            lvobjReport.PrintToPrinter(dblPrintValue, False, 0, 0)
            'End If
        ElseIf invVal = 2 Then
            Dim prd As New System.Drawing.Printing.PrintDocument
            lvobjReport.PrintOptions.PrinterName = prd.PrinterSettings.PrinterName
            If lvobjReport.PrintOptions.PrinterName = "" Or lvobjReport.PrintOptions.PrinterName = Nothing Then
                MyMessagebox.MyMessagebox.ShowMessage("Set Default Printer", "Global Funtions_UI", MessageBoxIcon.Information)
            End If

            NumberOfReturnPrints()
            lvobjReport.PrintToPrinter(dblReturnPrintValue, False, 0, 0)

        End If
    Catch ex As Exception
        MYERROR.WriteLogFile("GlobalFunctions_UI", "LoadCrystalReport", ex)
    End Try

End Sub


This error also occurs when you change page size setting from previous one and forgot to change code to force print using the previous page's settings.

eg. A5 > A4, but with code you are still setting page size to A5.


This error occurs when your parameters not matched in both reports & coding. May be your parameter name is wrong. So verify the parameters & parameter names are same in report & your coding.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜