Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX)) (rpt.SetParameterValue("@F_DATE", "Test"))


When i pass Parameter values not show the report
VB
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpApplication
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Web
Imports CrystalDecisions.ReportSource
Partial Class Reportviewer
    Inherits System.Web.UI.Page
    Public str As String
    Public rptname As String
    Public sf As String
    Private rpt1 As CrystalDecisions.CrystalReports.Engine.ReportDocument

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim con As New ConnectionInfo
        Dim con1 As New ConnectionInfo
        Dim db1 As Database
        Dim dbs As Tables
        Dim db As Table
        Dim tab As TableLogOnInfo
        rptname = Session("rptname") 
        If rptname = "" Then
            Exit Sub
        End If
        str = Convert.ToString(Session("Str")) '" {INV_HEAD.HInv_NO}='0000000001' "
        Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        With con
            .UserID = "sa"
            .Password = "sa"
            .DatabaseName = "tes"
            ' .ServerName = "Develope-PC"
            .ServerName = "server"
        End With
        rpt.Load(Server.MapPath("..\Report\INV_LIST1.rpt"))
      
        db1 = rpt.Database
        dbs = db1.Tables
        For Each db In dbs
            tab = db.LogOnInfo
            tab.ConnectionInfo = con
            db.ApplyLogOnInfo(tab)
        Next
          CrystalReportViewer1.SelectionFormula = str
    CrystalReportViewer1.ReportSource = rpt
'''''''''''''''''''''''''''

'this is my error line 
rpt.SetParameterValue("@F_DATE", "Test")


'''''''''''''''''''''
     CrystalReportViewer1.ShowFirstPage()
    CrystalReportViewer1.RefreshReport()

    End Sub
End Class

error message

VB
Server Error in '/e-Tasheel' Application.

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: 


Line 15:         crParameterDiscreteValue.Value = "@F_DATE"
Line 16:         crParameterFieldDefinitions =  cryRpt.DataDefinition.ParameterFields()
Line 17:         crParameterFieldDefinition = crParameterFieldDefinitions.Item("@F_DATE")
Line 18:         crParameterValues = crParameterFieldDefinition.CurrentValues
Line 19: 

Source File: C:\Users\surya\Desktop\Amjidh\e-Tasheel\Report\Default.aspx.vb    Line: 17 

Stack Trace: 


[COMException (0x8002000b): Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))]
   CrystalDecisions.ReportAppServer.DataDefModel.FieldsClass.get_Item(Int32 Index) +0
   CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions.get_Item(Int32 index) +81
   CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions.get_Item(String fieldName) +105
   Report_Default.Page_Load(Object sender, EventArgs e) in C:\Users\surya\Desktop\Amjidh\e-Tasheel\Report\Default.aspx.vb:17
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Posted
v2
Comments
On which line exactly, you get the exception ?
kalaiselvansurya 8-May-13 7:25am    
rpt.SetParameterValue("@F_DATE", "Test") this line i get the exception? @F_DATE this is my report field(From date field)
The parameter @F_DATE exists in Report or not ?

And if it is a Data field, how can you set a string "Test" in that. Please add one valid date to that and check whether exception is coming or not ?
kalaiselvansurya 8-May-13 11:22am    
i set date field also. now i call string value. only again same problem
Please check my answer.

After a lot of search I found one solution suggested in the answer Crystal report error Invalid index. Exception from HRESULT...[^].

Quote:
It sounds like that line is expecting a parameter index, not the specific name of the parameter.

Try adding parameter by index instead of name.

Hope it helps... :)
 
Share this answer
 
Try This
SQL
cryReport.Load(RepLocation)
        If TextBox1.Text <> "" Then
            cryReport.RecordSelectionFormula = "{Customer.CustomerID} = " & TextBox1.Text
        End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900