Pass parameters from .aspx page to crystal reports

Hi All,

I am new to ASP.NET.  I really need someone to help me on passing parameters from my .aspx page to my crystal report and viewing the report.

I have 4 search fields two of those fields are dates.  

Can anyone help me with this.
I am using crystal XI.


Thanks!
GoldenJagAsked:
Who is Participating?
 
frodomanCommented:
Well that would certainly explain why you're having problems with the samples.  The c# samples are here: http://support.businessobjects.com/communityCS/FilesAndUpdates/csharp_web_samples.exe.asp

I don't code in C# but I did find a sample on the Crystal forum that may help you:

public void Populate()
          {
               DataSet ds =  new DataSet("Courses");
               //Cart is a DataTable populated from another source on the site.
                        ds.Tables.Add(Cart);
                  //FlyerCourse.rpt is the subreport that has a parameter I need to send a guid.
               FlyerCourse rp = new FlyerCourse();
               ParameterFields paramFields = new ParameterFields ();
               ParameterField paramField = new ParameterField ();
               ParameterDiscreteValue discreteVal = new ParameterDiscreteValue ();
               ParameterRangeValue rangeVal = new ParameterRangeValue ();

               // The first parameter is a discrete parameter with multiple values.

               // Set the name of the parameter field, this must match a
               // parameter in the report.
               paramField.ParameterFieldName = "@BranchID";

               // Set the first discrete value and pass it to the parameter.
               discreteVal.Value = "FD03181F-C08D-4050-BA91-00F2DDB4410E";
               paramField.CurrentValues.Add (discreteVal);
               // Add the parameter to the parameter fields collection.
               paramFields.Add (paramField);

               // Add the second parameter to the parameter fields collection.
               paramFields.Add (paramField);

               // Set the parameter fields collection into the viewer control.
               CRV1.ParameterFieldInfo = paramFields;
               
               rp.SetDataSource(ds);
               DataBind();
               Cart.Dispose();
               ds.Dispose();
          }
0
 
frodomanCommented:
There are a couple of ways to do it - you can pass parameters through the ReportDocument object or through the CrystalViewer.  I'd advise that you download these sample applications ( http://support.businessobjects.com/communityCS/FilesAndUpdates/vbnet_web_samples.exe.asp ) and look at the ones related to parameters.  Most of the code in the discrete parameters sample can probably be pasted right into your application.

Note that the samples were written for CR9 but they work with XI
0
 
GoldenJagAuthor Commented:
frodoman,

I am having issues when trying to open these samples.
I get an error stating "UNABLE TO GET PROJECT FILE FROM WEB SERVER"......

Any idea what that means or what i need to do to fix it.

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
frodomanCommented:
Sorry, I haven't seen that.  Perhaps try opening just a single .aspx page instead of opening the whole project?  Generally it's one page in each project that does all of the work - sometimes with a class file also.
0
 
GoldenJagAuthor Commented:
frodoman,

I really appreciate your help. But i am not having any luck with this sample projects.  I am unfamiliar with .net so i dont know what to look for.  

I will need a step by step explaination on how to do this.

I have written CR in VB6 so i am familiar with CR.  i just dont know how to pass params from .aspx page.


Is there something else you can give me besides those examples.


Thanks for your help.
0
 
frodomanCommented:
A simple case - just use the SetParameterValue method of the ReportDocument object:

Dim reportDocument = new ReportDocument()
reportDocument.Load(strLocation)
reportDocument.SetDatabaseLogon(dbUser,dbPass)

reportDocument.SetParameterValue(paramName,paramValue);
reportDocument.SetParameterValue(paramName,paramValue);
reportDocument.SetParameterValue(paramName,paramValue);

reportDocument.PrintOptions.PrinterName = printerName;
reportDocument.PrintToPrinter(1, false, 0, 0);

0
 
GoldenJagAuthor Commented:
Ok frodoman, i think i know where there is some confusion.  I am using a file with ext aspx.cs (so i guess i am using c#) ?

so since i cant use " Dim " how would i use it in c#.



sorry for being an idiot but i am just learning :)

thanks for being patient.
0
 
GoldenJagAuthor Commented:
i am using a report viewer...if that helps any.
0
 
GoldenJagAuthor Commented:
OK i found this snipplet of code on MSDN.  i tried to get it to run put i am doing something wrong.

Now i have a page called Search.aspx (this contains the textboxes for users to enter info for a search).  I will like to take that info and pass it to CR with those textbox values as parameters and display my reports. (query is a stored proc)

the form that i have the CRViewer on is called Report_View.aspx and the actual CR is called Enrolls.rpt.

Could someone help me piece this together.


[C#]
// Declare variables needed to pass the parameters
// to the viewer control.
ParameterFields paramFields = new ParameterFields ();
ParameterField paramField = new ParameterField ();
ParameterDiscreteValue discreteVal = new ParameterDiscreteValue ();
ParameterRangeValue rangeVal = new ParameterRangeValue ();

// The first parameter is a discrete parameter with multiple values.

// Set the name of the parameter field, this must match a
// parameter in the report.
paramField.ParameterFieldName = "Customer Name";

// Set the first discrete value and pass it to the parameter.
discreteVal.Value = "AIC Childrens";
paramField.CurrentValues.Add (discreteVal);

// Set the second discrete value and pass it to the parameter.
// The discreteVal variable is set to new so the previous settings
// will not be overwritten.
discreteVal = new ParameterDiscreteValue ();
discreteVal.Value = "Aruba Sport";
paramField.CurrentValues.Add (discreteVal);

// Add the parameter to the parameter fields collection.
paramFields.Add (paramField);

// The second parameter is a range value. The paramField variable
// is set to new so the previous settings will not be overwritten.
paramField = new ParameterField ();

// Set the name of the parameter field, this must match a
// parameter in the report.
paramField.ParameterFieldName = "Customer ID";

// Set the start and end values of the range and pass it to the
// parameter.
rangeVal.StartValue = 42;
rangeVal.EndValue = 72;
paramField.CurrentValues.Add (rangeVal);

// Add the second parameter to the parameter fields collection.
paramFields.Add (paramField);

// Set the parameter fields collection into the viewer control.
crystalReportViewer1.ParameterFieldInfo = paramFields;






0
 
GoldenJagAuthor Commented:
i guess what i really need to know is what i need declare on each page and where i need to declare it to get this report to work.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.