cancel
Showing results for 
Search instead for 
Did you mean: 

An unhandled exception 'System.Runtime.InteropServices.COMException

Former Member
0 Kudos

I have designed a crystal report based on the typed dataset so i am passing the dataset as source like

rpt.SetDataSource(dsTempDataSet.Tables("StateTimeStudyReport"))

since my crystal report is having one parameters values so i want to pass the value for this parameter but when i am trying to access the parameter from the report using

Dim MyParamValues As New ParameterValues

MyParamValues = rptTimesheetState.DataDefinition.ParameterFields("piPositionID").CurrentValues

i am getting the following exception

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in CrystalDecisions.CrystalReports.Engine.dll

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

I have noticed while debugging that when i set the datasource for the crystal report instance, all the parameters list is getting vanished / deleted and its count showing Zero.

and i set the datasource property after inistializing the parameters values first, i am getting the exception "Missing parameters values". So in both cases i am getting the different exception

I am using the following environment:

OS : windows 2003 server

.Net framework: 2.0

VS : 2005

Please let me know the solution. I am tried a lot with all the permutaion and combinations.

thanks

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hello, Amrendra;

I ran your version of the parameter code in my application and I also get an error. "Object not set to an instance of an object."

Before you can get the values from the parameter field you have to define it.

Dim MyParameterFieldDefinition As ParameterFieldDefinition

And get the initialise the property from the report:

MyParameterFieldDefinition = rptPositionDetail.DataDefinition.ParameterFields.Item("psPosition")

In your code it would be:

' Set the data source for the report

rptPositionDetail.SetDataSource(dsTempDataSet.Tables("PositionDetails"))

'set up parameters for report

Dim MyParameterFieldDefinition As ParameterFieldDefinition

Dim MyParamValues As New ParameterValues

Dim dvPosition As New ParameterDiscreteValue

'Get the parameter field from the report

MyParameterFieldDefinition = rptPositionDetail.DataDefinition.ParameterFields.Item("psPosition")

'Then you can use

MyParamValues = MyParameterFieldDefinition.CurrentValues

'Or the line you had, but not both.

MyParamValues = rptPositionDetail.DataDefinition.ParameterFields("psPosition").CurrentValues

dvPosition.Value = sPosition

MyParamValues.Add(dvPosition)

rptPositionDetail.DataDefinition.ParameterFields("psPosition").ApplyCurrentValues(MyParamValues)

That should work.

Elaine

Former Member
0 Kudos

Hello, Amrendra;

Next I would like you to take a copy of your report and remove the parameter. If you have used it in the selection formula or a formula field you will have to remove it first.

Comment out your parameter code.

Run the report without the parameter.

Does it succeed?

If that works, create a small application with a Crystal Viewer on the form. Run the report with the parameter but leave the code commented out so that the viewer will prompt for a value. Enter the value at the prompt.

Does that work?

Elaine

Former Member
0 Kudos

Hello Elaine,

without parameter, its running file.

Only throwing exception when there is any parameters on the report.

Without parameter, all reports are running fine.

thanks

Amrendra

Former Member
0 Kudos

Hello, Amrendra;

I would like to simplify the code as a test. Please comment out all of your parameter code and use the following convenience method with a hard coded valid value. Does it work?

' Set the data source for the report

rptPositionDetail.SetDataSource(dsTempDataSet.Tables("PositionDetails"))

'Pass the parameter hard coding the parameter name and a valid parameter value

rptPositionDetail.SetParameterValue("psPositionID". "idValue")

Let me know what you find.

Elaine

Former Member
0 Kudos

Hello Elaine,

I have already tried that one and got the same exception.

thanks

Former Member
0 Kudos

Hello, Amrendra;

The fact that the parameter list is affected when you pass the dataset tells me the error may be happening before the parameters are accessed.

I would like to test the data in the designer. What version of Crystal Reports are you using? Version 10.2 that ships with Visual Studio .NET 2005 or a later version? Have you installed any updates or Service Packs for Crystal Reports?

Just before the line where you pass the data in your application, I would like you to add one line of code:

' Create an XML file with the correct datatypes

' Add the following line

' dsTempDataSet.WriteXml("C:\Temp\XMLdata.xml", XmlWriteMode.WriteSchema)

' Set the data source for the report

rptPositionDetail.SetDataSource(dsTempDataSet.Tables("PositionDetails"))

Run the application so it stops after you pass the dataset to the report. Now you have the data exactly as it is created saved in an XML file.

Open a copy of your report in the Crystal Reports designer. Go to Database|Set Datasource location.

Choose "Create New Connection".

Choose ADO.NET(XML)

Under "File Path:", point to the XML file you just created from your code, e.g. "C:\Temp\XMLdata.xml"

Highlight the table name in the new connection and the table name in the original connection. Click 'Update'.

Close the dialog and choose Database, Verify Database.

What happens during these steps?

Do you get the message "The database is up to date" or another response?

Is your parameter still visible?

Are there any other parameters?

How is the parameter name displayed in the designer? e.g. "psPosition" or "@psPosition"?

I will be watching for your reply.

Elaine

Former Member
0 Kudos

Hello Elaine,

thanks for the prompt reply.

Yaa i have Crystal report version 10.2.3600.0 which is included into the VS 2005. I have also installed the Service pack 1 for crystal report for VS 2005.

I have done the steps which you have mentioned here.

Results are as follows:

After creating the copy of the crystal report and doing the mentioned steps i got the message "The Database is upto Date".

Parameter are still on my report and its name is "psPosition".

No other parameters are visible on the report.

thanks

Former Member
0 Kudos

Hello, Amrendra;

When you designed your report, what datasource did you use?

Look in the Crystal Reports designer under Database|Set Datasource location. What are the properties of the database?

Did you create the parameter field in the report or was it automatically created by connection to a Stored Procedure?

There are two ways to set the parameter value. The full method as in the following sample code:

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Public Class Form1

Inherits System.Windows.Forms.Form

''CR Variables

Dim crReportDocument As CRParams

Dim crParameterFieldDefinitions As ParameterFieldDefinitions

Dim crParameterFieldDefinition As ParameterFieldDefinition

Dim crParameterValues As ParameterValues

Friend WithEvents CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer

Dim crParameterDiscreteValue As ParameterDiscreteValue

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

''Create an instance of the strongly-typed report object

crReportDocument = New CRParams()

''Get the collection of parameters from the report

crParameterFieldDefinitions = crReportDocument.DataDefinition.ParameterFields

''Access the specified parameter from the collection

crParameterFieldDefinition = crParameterFieldDefinitions.Item("Country")

''Get the current values from the parameter field. At this point

''there are zero values set.

crParameterValues = crParameterFieldDefinition.CurrentValues

''Set the current values for the parameter field

crParameterDiscreteValue = New ParameterDiscreteValue()

crParameterDiscreteValue.Value = "Canada" '1st current value

''Add the first current value for the parameter field

crParameterValues.Add(crParameterDiscreteValue)

''Since this parameter allows multiple values, the discrete value

''object needs to be reset. Destroy the previous instance and create

''a new instance.

crParameterDiscreteValue = Nothing

crParameterDiscreteValue = New ParameterDiscreteValue()

crParameterDiscreteValue.Value = "USA" '2nd current value

''Add the second current value for the parameter field

crParameterValues.Add(crParameterDiscreteValue)

''All current parameter values must be applied for the parameter field.

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

''Set the viewer to the report object to be previewed.

CrystalReportViewer1.ReportSource = crReportDocument

End Sub

You can also use a convenience method that will work for one value as in the following article:

[Click|https://bcp.wdf.sap.corp/sap/sapnotes/display/0001216238]

Elaine

Former Member
0 Kudos

thanks for the reply.

Data source used in the report as ADO.net TypedDataset so connection information while creating report.

And Parameters are user created parameters, not automatically created parameters list.

Code are as follows:

Dim rptPositionDetail As New crPositionDetail

Dim sPosition As String = "0256"

Me.Cursor = Cursors.WaitCursor

rptPositionDetail.ReportOptions.EnableSaveDataWithReport = False

'fill dataset with query results and attach to report

Dim dsTempDataSet As DataSet = Nothing

Try

' fill the dataset by calling the below function with parameters

dsTempDataSet = ReadStoredProcedure_DataSet("usp_RptPositionIDList" , "66")

dsTempDataSet.Tables(0).TableName = "PositionDetails"

Catch ex As Exception

ShowApplicationError("Query for position detail info failed" & ex.Message, _

"Position Detail Report")

Me.Cursor = Cursors.Default

Exit Sub

End Try

' Set the data source for the report

rptPositionDetail.SetDataSource(dsTempDataSet.Tables("PositionDetails"))

'set up parameters for report

Dim MyParamValues As New ParameterValues

Dim dvPosition As New ParameterDiscreteValue

MyParamValues = rptPositionDetail.DataDefinition.ParameterFields("psPosition").CurrentValues

' Getting the exception here while trying to access the parameters from the report

dvPosition.Value = sPosition

MyParamValues.Add(dvPosition)

rptPositionDetail.DataDefinition.ParameterFields("psPosition").ApplyCurrentValues(MyParamValues)

'show print dialog to select printer

Dim dlgPrintDialog1 As New PrintDialog

Dim docPrintDocTemp As New System.Drawing.Printing.PrintDocument

Dim dgrResult As DialogResult

dlgPrintDialog1.Document = docPrintDocTemp

Dim FileName As String = m_PDFFilePath + "PositionDetailsReport.pdf"

Try

rptPositionDetail.ExportToDisk(ExportFormatType.PortableDocFormat, FileName)

rptPositionDetail.Close()

Process.Start(FileName)

Catch ex As Exception

CheckIOException(ex.GetType.ToString, "mnuReportsPositionPositionDetail_Click")

End Try

End If

rptPositionDetail.Dispose()

Me.Cursor = Cursors.Default