Print Page | Close Window

Listing 16-4 Runtime Error

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=331
Printed Date: 31 Oct 2024 at 3:02pm


Topic: Listing 16-4 Runtime Error
Posted By: Marv
Subject: Listing 16-4 Runtime Error
Date Posted: 15 Mar 2007 at 3:05pm
I am a complete newbie, but I think I got the C# code for Listing 16-4 (SetParameterDiscreteWithReport) exactly right.  It compiles correctly.
 
But I get an error when I run it:  "Index was outside the bounds of the array".   The error occurs at SubreportName in 
 
ParameterFieldDefinition=
MyReport.DataDefinition.ParameterFields[ParameterName, SubreportName];
 
I am passing the method "" as SubreportName, since I don't have a Subreport.  But I get the runtime error with this empty field.
 
I am working in Visual Studio 2005, if that makes any difference.
 
Am I missing something obvious?
 
Thanks...Marv


-------------
Marv



Replies:
Posted By: BrianBischof
Date Posted: 15 Mar 2007 at 3:18pm
I still need to do more work with VS 2005. But since there is no sub-report, only pass one parameter. Just ignore the second parameter.

The error usually means that you are passing the wrong parameter name to the report. What I would do (I actualy just did this today for a co-worker), is go into debug mode and break on that line. Then look at the parameter collection and get the name of the parameter. Then you will know if you are passing it the correct name or not (you're name should be identical to what it is expecting).

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: Marv
Date Posted: 15 Mar 2007 at 3:39pm
Brian --
You are quick to respond and you are correct.  When I remove the references to ReportName the code works fine.  I am OK with that, since I am not using a subReport.
I did check the value of MyReport.ParameterFields[0].ReportName, and "" is correct.  So I am not certain why the blank parameter is "out of range".  I guess it is some kind of a change in VS2005??
 
Thanks for your speedy response!  Marv
 
 


-------------
Marv


Posted By: BrianBischof
Date Posted: 15 Mar 2007 at 4:15pm
I don't get it. You have no parameter and you are trying to assign one? Don't write any code if there is no parameter to code for.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: Marv
Date Posted: 15 Mar 2007 at 4:30pm

Brian --

Your example (Listing 16-9 Modify parameters using the viewer control, pg 339):

SetParameterDiscreteWithViewer(crystalReportViewer1, "CustomerID", "DotNet Tech", "");

The last parameter (i.e. "") breaks on run time.  My workaround is to rewrite SetParameterDiscreteWithViewer() without the string SubreportName parameter.
 
The workaround is OK, but I can no longer use the same method if I DO have a subreport.  I am used to VBA, when a parameter like this would be tagged Optional.


-------------
Marv



Print Page | Close Window