Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Listing 16-4 Runtime Error Post Reply Post New Topic
Author Message
Marv
Newbie
Newbie
Avatar

Joined: 01 Mar 2007
Location: United States
Online Status: Offline
Posts: 7
Quote Marv Replybullet Topic: Listing 16-4 Runtime Error
    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
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
IP IP Logged
Marv
Newbie
Newbie
Avatar

Joined: 01 Mar 2007
Location: United States
Online Status: Offline
Posts: 7
Quote Marv Replybullet 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
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
IP IP Logged
Marv
Newbie
Newbie
Avatar

Joined: 01 Mar 2007
Location: United States
Online Status: Offline
Posts: 7
Quote Marv Replybullet 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
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.032 seconds.