?
Solved

Pass parameters from .aspx page to crystal reports

Posted on 2006-05-04
10
Medium Priority
?
1,579 Views
Last Modified: 2007-12-19
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!
0
Comment
Question by:GoldenJag
  • 6
  • 4
10 Comments
 
LVL 42

Expert Comment

by:frodoman
ID: 16606722
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
 

Author Comment

by:GoldenJag
ID: 16607106
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
 
LVL 42

Expert Comment

by:frodoman
ID: 16607203
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:GoldenJag
ID: 16607486
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
 
LVL 42

Expert Comment

by:frodoman
ID: 16608063
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
 

Author Comment

by:GoldenJag
ID: 16609189
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
 

Author Comment

by:GoldenJag
ID: 16609231
i am using a report viewer...if that helps any.
0
 
LVL 42

Accepted Solution

by:
frodoman earned 2000 total points
ID: 16609394
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
 

Author Comment

by:GoldenJag
ID: 16609708
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
 

Author Comment

by:GoldenJag
ID: 16609799
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question