Passing Multiple Parameters to a Crystal Report Programmatically

Passing a parameter to a Crystal Report is easy; all you need to do is drop a ready-made parameter field from the Field Explorer to your report and when the report is loaded, the user is asked for the parameter's value automatically.

Passing multiple parameter values to a report programmatically is a bit trickier.

First, you have to use the correct parameter type. In the Field Explorer, add a new parameter and make sure that Allow multiple values and Discrete value(s) are selected. Next, drag the parameter from the Field Explorer on your report. Then open the Select Expert (right-click your report and choose Report | Select Expert...), double-click the field you're setting the parameter for (Country in this example), choose is equal to from the first drop-down, choose your parameter (?Country) from the second drop-down and click OK.

The next step is to add the code that passes the values for the parameters at run-time. The example below uses hard-coded values for a parameter that filters the report based on the country name, but in reality you can substitute these hard-coded values with any values you like. For example, you can retrieve them from a database, a user preference stored in the registry, or retrieve them from text boxes placed on a Windows form. Just make sure that the ParameterFieldName matches the name of the parameter in the Field Explorer (minus the question mark). Don't forget to import the CrystalDecisions.Shared namespace.

Add the following code to the click handler of a button, the load handler of a form, or any other method that is applicable in your situation:

using CrystalDecisions.Shared;
...
private void ParamButton_Click(object sender, System.EventArgs e)
{
  // Create parameter objects
  ParameterFields myParams = new ParameterFields();
  ParameterField myParam = new ParameterField();
  ParameterDiscreteValue myDiscreteValue = new ParameterDiscreteValue();

  // Set the ParameterFieldName to the name of the parameter
  // created in the Field Explorer
  myParam.ParameterFieldName = "Country";
			
  // Add first country
  myDiscreteValue.Value = "USA";
  myParam.CurrentValues.Add(myDiscreteValue);
			
  // Reuse myDiscreteValue, and assign second country
  myDiscreteValue = new ParameterDiscreteValue();
  myDiscreteValue.Value = "Netherlands";
  myParam.CurrentValues.Add(myDiscreteValue);
				
  // Add param object to params collection
  myParams.Add(myParam);
		
  // Assign the params collection to the report viewer
  myCrystalReportViewer.ParameterFieldInfo = myParams;
		
  // Assign the Report to the report viewer.
  // This method uses a strongly typed report,
  // but other methods are possible as well.
  myCrystalReportViewer.ReportSource = MyReportObject;
}

Assigning the ParameterFields object to the ParameterFieldInfo of the CrystalReportViewer object programmatically will also suppress the default dialog asking for parameters that normally appears when you open a report with parameters.


Where to Next?

Wonder where to go next? You can read existing comments below .


Consider making a donation
Please consider making a donation using PayPal. Your donation helps me to pay the bills so I can keep running Imar.Spaanjaars.Com, providing fresh content as often as possible.



Feedback by Other Visitors of Imar.Spaanjaars.Com

On Tuesday, November 30, 2004 1:06:35 PM Thien Nguyen said:
QuickDocId: 310

I need help if possible:
I have a crystal report design in develoment site (using Seagate Crystal Report) passing parameter fields and it works fine when I click refresh, it asks me to enter a ranges of date.  But when I try to display it using IE, it gives me a error meassge some thing like "IE has encountered a problem and needs to close...." I don't know what is going on.  Is there something with the .rpt file or something with the server setup?  Please help.  Thanks.  -Thien

PS: I have included my email address, you can contact me if you need to ask me something.  Thanks again!
On Thursday, January 06, 2005 6:34:07 PM Vikbol In said:
Please help with CrystalReport.
I have a main report that has embeded subreport. The main report links to subreport through a UserID database field, and I assign datasource to both report at runtime by using ReportDocument.SetDataSource().
When I view the report using CrystalViewer control, it prompt me to enter parameter discret value. How do I suppress this dialog?

Thank you, in advance, for your help.
On Saturday, January 15, 2005 12:17:06 PM Praveen said:
Dear I did same as you mentioned above. I am able to pass the first value in the parameter field. But second value i could not. Plese help me.

regards,

Praveen
On Tuesday, January 25, 2005 3:23:01 PM manoj ahir said:
hello
i am using crystal reports in asp.net, i have report which has some master record and for each master record there is on demand subreport.

when i have linked subreport to main report it has created one parameter in subreport to link record of master report.

now my problem is i am not able to set subreport parameter from asp.net coding since without seting it it gives error of missing parameter field.

Any reply will be greatly appreciated.
On Friday, February 18, 2005 6:04:45 PM Smitha said:
Am having 'sortby' parameter in main report and 'sortby' parameter in subreport. I call from VB.net with foll code. GMparmrep2 = form
and sortby is a combo box value which am passing to Crystal. For both the main and subreport, am passing same 'sortby' values.
        parmcmbSortBy.ParameterFieldName = "sortby"
        discretevalue.Value = GMparmrep2.sortby
        parmcmbSortBy.CurrentValues.Add(discretevalue)
I dont want CR to ask for parameter becoz it is already passed frm Combobox. For main report, it is not asking for 'sortby' value but Crystal report subreport is askin for 'sortby' parameter.
Pls help me with this. Its very urgent and i wil b thankful if u can help.
On Wednesday, February 23, 2005 6:41:06 AM none none said:
this stupid code does't work
\inetpub\wwwroot\WebApplication6\WebForm1.aspx.cs(34): The type or namespace name 'ParameterField' could not be found (are you missing a using directive or an assembly reference?)
On Wednesday, February 23, 2005 7:05:32 AM Imar Spaanjaars said:
Of course this stupid code works.

You just have to make sure that your project has the right references to the CR assemblies, like CrystalDecisions.Shared (D:\Program Files\Common Files\Crystal Decisions\1.1\Managed\CrystalDecisions.Shared.dll) and that you add a using or Imports ststatement for the Shared namespace at the top of your code.....

Imar
On Saturday, March 19, 2005 5:59:41 AM Kunal Sagwaria said:
I am facing problem in sub report .
first i created one report(first).
after that i created another report sepratly in my project (second).
   now i want to call that second report in first report .
   i puted that second report on first report.
   but i don't know code for connecting this two report.
    i want that what will be the code for connecting  sub report with main report
On Saturday, March 19, 2005 10:10:44 AM Imar Spaanjaars said:
Hi Kunal Sagwaria,

For technical questions not directly related to an article posted on this site, please use a forum like http://p2p.wrox.com/

Thanks,

Imar
On Sunday, March 20, 2005 7:18:41 PM Om said:
Wonderful article

It helped me a lot to solve my problem.

Thanks...
On Monday, March 21, 2005 7:23:25 PM Chuck said:
Thanks.  I am using a DB2 database via db2 client.  The only way this parameter passing would work from c# is when I changed the Crystal Report V10 connection type to OLE for the report.  Why?
On Monday, March 21, 2005 7:30:55 PM Imar Spaanjaars said:
I have no idea. I hardly have any experience with DB2.

Try a technical forum like http://p2p.wrox.com for a better answer.

Cheers,

Imar
On Tuesday, April 05, 2005 3:33:07 PM Eric said:
I don't see where you define MyReportObject
On Tuesday, April 05, 2005 4:19:38 PM Shirley said:
I have a crystal report that is called from my VB Web application.  It takes 2 parameters.  On the test server it works, but when I run it on the production server it fails.  I get an error message "Unable to connect incorrect logon parameters".  
On Tuesday, April 05, 2005 9:58:06 PM Imar Spaanjaars said:
It's not in there, as I assumed you know how to create a report source:

// Assign the Report to the report viewer.  
// This method uses a strongly typed report,  
// but other methods are possible as well.  myCrystalReportViewer.ReportSource = MyReportObject;

So, just create a report source as you would normally do, either by creating a strongly typed one at dev. time, or load one dynamically.

For the logon problem: make sure the connection string you're using is valid on your production server as well, or dynamically change the configuration at run-time.

Cheers,

Imar
On Wednesday, April 06, 2005 10:05:09 AM SKILITES said:
Shirley  
I would rather add a little to  Imar Spaanjaars 's comment to include a little function to your code which by default or when required change the server logins for the reports.
You can try the below . Further always remember if you are using two server like production and test , on both the servers the user accessing the table/view has the permissions and the report has to be checked "using windows authentication" when created ( if you are in side LAN ) .This way you only have to check on network rights rather than
SQL or DB2 rightrs.

**************************************
Dim crtableLogoninfos As New TableLogOnInfos()
            Dim crtableLogoninfo As New TableLogOnInfo()
            Dim crConnectionInfo As New ConnectionInfo()
            Dim CrTables As Tables
            Dim CrTable As Table
            Dim TableCounter

            'Dim xPV As New Object()
            With crConnectionInfo
                .ServerName = srvrName
                .DatabaseName = databaseName
            End With

            'CrTables = xPV.Database.Tables
            CrTables = obj.Database.Tables
            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            Next
            Return obj

On Wednesday, April 06, 2005 10:13:56 AM Imar Spaanjaars said:
Hi SKILITES,

Thanks for your post. When I typed my comments I didn't have access to my development machine, and unfortunately, I cannot remember code snippets like this without using copy and paste ;-)

This was what I had in mind though.

Cheers,

Imar
On Thursday, April 07, 2005 9:07:04 PM Eric said:
Thanks for the code snippet.  Worked like a champ.
On Monday, April 11, 2005 3:03:39 PM kevin mitchell said:
I'm having problems with a report that is using a date range.  I've written a procedure that will open any report I have by displaying different boxes for input.  It seems that any value i enter in the beginDate parameter field is ignored and only those records that are = to the endDate parameter are shown.  Is there a way to pass 2 values on the same column and get all records in that date range?

Please help.  I'm stumped.

thanks

Kevin
On Wednesday, April 13, 2005 6:38:11 PM Imar Spaanjaars said:
Hi Kevin,

For technical questions not directly related to an article posted on this site, please use a forum like http://p2p.wrox.com/

Thanks,

Imar
On Friday, April 15, 2005 2:50:10 AM vilas said:
This article is very good.
Can you guide me how the runtime crystal reports are generated.
If you have any demo/small  project then pl.send it to me.
On Friday, April 15, 2005 7:16:52 AM Imar Spaanjaars said:
That would work pretty much the same as working with a report without parameters or Logon information....

Just change the last line of my initial code example to something like this:

MyReportObject = New YourReportName
myCrystalReportViewer.ReportSource = MyReportObject
myCrystalReportViewer.DataBind()

Optionally, you can set the LogonInfo with a helper method. Just add the following line after the MyReportObject = New YourReportName line:

SetLogonInfo(MyReportObject)

Private Sub SetLogonInfo(ByVal myReport As ReportClass)
  Dim myDbConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
  With myDbConnectionInfo
    .ServerName = "YourServerName"
    .DatabaseName = "YourDatabaseName"
  End With

  Dim myTableLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo
  Dim myDatabase As CrystalDecisions.CrystalReports.Engine.Database = myReport.Database
  Dim myTables As CrystalDecisions.CrystalReports.Engine.Tables = myDatabase.Tables
  Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
  For Each myTable In myTables
    myTableLogonInfo = myTable.LogOnInfo
    myTableLogonInfo.ConnectionInfo = myDbConnectionInfo
    myTable.ApplyLogOnInfo(myTableLogonInfo)
  Next
End Sub


Finally, take a look at the Load method the ReportDocument class. That allows you to dynamically load reports from disk: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlrf/html/crlrfreportdocumentclassloadmethodtopic1.asp?frame=true
On Thursday, April 21, 2005 9:44:04 AM asad said:
nice
On Wednesday, April 27, 2005 5:08:07 PM jdrs said:
I'm trying to apply the code shown in the article to passing a pair of dates to their respective parameters from a C# .NET project.  It all works except that I still get the dialogue asking for the values for the parameters.  The correct values are already in place, but I'd rather not see the dialogue at all.  Do you have any hints?  I have included your line:

myCrystalReportViewer.ParameterFieldInfo = myParams;

Thanks in advance for any help you are able to provide.
On Sunday, May 01, 2005 6:03:41 PM zohreh said:
I wana pass more then one parameter to crystal report .but i don't know
what can i do this?
i success for one parameter.
plz helm me
On Sunday, May 01, 2005 6:53:22 PM Imar Spaanjaars said:
To everyone posting technical questions as a comment on this article: please post your question on a forum like http://p2p.wrox.com/

A forum is a *much* better place for asking technical questions and getting fast and correct answers. Unfortunately, I don't have the time to answer each question I get on this site personally.

Thanks,

Imar
On Monday, May 09, 2005 7:23:36 AM thomas said:
i tried the code given here to pass the values to formula fields in the report but nothing is displayed in the report can someone help me to correct it.

thomas
On Monday, May 09, 2005 7:16:47 PM Imar Spaanjaars said:
To everyone posting technical questions as a comment on this article: please post your question on a forum like http://p2p.wrox.com/

A forum is a *much* better place for asking technical questions and getting fast and correct answers. Unfortunately, I don't have the time to answer each question I get on this site personally.

Thanks,

Imar
On Wednesday, June 01, 2005 9:43:38 PM Tamara Dillard said:
Thanks for the great article!  It was just what I needed :)
On Saturday, June 04, 2005 5:06:42 AM Mayank Choubey said:
Hi ,

     I tried above coding and its working...its too good.Actually ihave problem that i am trying to pass parameters to crystal reports 8 using vb 6.0 but it is giving runtime error  '20553' :  invalid parameter field name
.I am not getting it.Pz help me out.

Any help regarding this will  be greatly appreciated.

Regards,
Mayank
On Thursday, June 30, 2005 2:26:00 PM smc said:
How do we pass the parameters to two subreports in the main crystal report?

Thank you

smc
On Monday, July 04, 2005 6:31:37 PM John Gonzalez said:
Awesome. Just what I needed, quick and no messing about. Genius! Many thanks.... I'll be bookmarking your site for sure.
On Wednesday, July 20, 2005 10:19:28 AM hari said:
iam using dotnet ver1.1,in this version iam unable to pass parameters to
crystal reports from asp.net.if any one how to pass parameters in ver 1.1
please help me
On Wednesday, August 10, 2005 10:34:44 AM imran parvez said:
sir,
i used above code for passing the parametter but it not work it will send the error is :
"Error in File C:\DOCUME~1\MIS2\ASPNET\LOCALS~1\Temp\temp_5a6590ca-fe64-497a-abb0-45dec38ec825.rpt: Unable to connect: incorrect log on parameters. "

please solve the problum

thanks & regards
imran
On Wednesday, August 10, 2005 5:39:06 PM Imar Spaanjaars said:
Did you search Google for the error: "Unable to connect: incorrect log on parameters"?? There are loads of results that can help you fix this problem.

Cheers,

Imar
On Sunday, February 05, 2006 6:11:34 AM Shoaib Ata said:
I have a main report that has embeded 02 subreports. The main report contains Emp Master table and leaves master table while both subreports contain DB tables of different leaves type availed by Emp. I have linked  both subreports through EmpID, and LeaveID database fields of main report and I want to display employee leave availed data in a particular year. I also have created a parameter date type field in main report. Problem is that the main report is not passing parameter to both subreport and demand individual parameter input for both subreport. How can I solve this problem. Please help me at the earliest, I have to submit my project.
On Sunday, February 05, 2006 9:41:35 AM Imar Spaanjaars said:
To everyone posting technical questions (and that does include you, Shoaib Ata) as a comment on this article: please post your question on a forum like http://p2p.wrox.com/

A forum is a *much* better place for asking technical questions and getting fast and correct answers. Unfortunately, I don't have the time to answer each question I get on this site personally.

Thanks,

Imar
On Tuesday, April 18, 2006 4:20:35 PM Kamalakar M said:
Hi there, the above mentioned code was very much usefull....
I got things right but i am not able to add more than one values.
It is taking only the first value and not showing both values....
CAn u please help me on this matter....
May be i am doing some thing a little wrong.....But i am no able to trace it...

Please help me if u can....

Regards
kamalakar
On Wednesday, April 19, 2006 6:46:34 AM Imar Spaanjaars said:
Hi Kamalakar ,

Are you sure you set up the param fields correctly? Are both used to filter the data for the report?

If that doesn't help, I suggest you post your question at http://p2p.wrox.com and provide a bit more information about your report.

Cheers,

Imar
On Tuesday, May 02, 2006 8:33:20 AM Jeelani said:
Dear Friends,

i made a vb6 program with crystal report 9. i created one parameter in crystal report and i wrote the program from vb such as

Me.cryReport.ParameterFields(0) = "SText;" & Trim Me.comVoucharType) & ";False"

when i preview the report that's ok. but parameter dialog box is always open. i want avoid parameter dialog box. i want preview without showing dialong box.

Please help me any one.
On Wednesday, May 03, 2006 8:44:51 AM nikhil marathe said:
hello sir i find u r feed back ans r fabulaus so
i do have question
i am faceing a prob while working on project
my question is
i create check box field and stored value true and false in data base
that value i want to retrive on reports
my problem is how would i retrive value from database and according to that display image either checked or unchecked
On Thursday, May 11, 2006 11:46:28 AM asad khan said:
I am a fresh graduate and at a junior level programmer at software house i was facing too much problems when passing parameters to crystal reports even after scanning as many pages from google as i can but this was the article in which i faced no problem and now i am able to pass parameters with out thinking at all.
this was the best article
On Thursday, May 11, 2006 11:34:55 PM Venkat said:
Hi,

I have created report in CrystalReports10, this preport is having parameter field.
This report  is with mutiple pages (each record on separate page).

I added this report to a Asp.net page, and I am loading the report on pageLoad event and I am passing the parameter,
the report loads correctly , the problem is with Navigation button on the tool bar,
when I click on the next button, the second page(second record from the database table) in the report gets loaded but after that the next button doesnt work, and again when I print the report it prints without data only template is printed.

Note:The same kind of report without paremeters is working fine(navigation and print is working fine).

I think it has something to do with parameters.

Can you help me in resolving this issue.
Thanks
On Thursday, June 22, 2006 8:28:38 AM sohail said:
Hi,

i have used a formula field with named "@heading" in crystal report. now i want to pass the value to this formula field in asp.net(C#)
so wht will be the code ..plz help me out

Thanks,
On Friday, June 23, 2006 6:41:53 AM Kool said:
Hi,

I need to design crystal reports XI at runtime from VB.net as front-end and oracle 8i as the back end.

Kindly do the needful,
Thanks in advance,
Regards
Kool
On Wednesday, July 05, 2006 10:43:01 AM Richard Measey said:
Hi,

I've had trouble getting rid of the parameter dialog box for a report that I supply the parameters to via .net 2.0. I've used your code at the very top of the page, but I am still being prompted. Do you have any suggestions as to what I might potentailly be doing wrong etc...? Help would be very much appreciated.
On Wednesday, July 05, 2006 9:09:50 PM Imar Spaanjaars said:
Hi Richard,

Sorry, no I don't. It's been a long time since I used Crystal Reports, and I haven't used it in .NET 2 yet. Try posting your question at a forum like http://p2p.wrox.com.

Cheers,

Imar
On Tuesday, July 11, 2006 4:47:14 AM Tanmay Choudhury said:
How do I assign values in text at runtime in crystal report 9.1 in asp.net 2003?
On Monday, August 14, 2006 5:32:39 PM Lizy said:
HI!
I have been traying to pass a multiple value parameter values from an asp code to a crystal report viewer.... the thing is that it always pass only the first element even do i have verified that the loop is working properly.

i paste the part of the code

for i=0 to termine-1
  CodigoPrefijo = cstr(Grupos(i))
  
  Session("oRpt").ParameterFields.GetItemByName
  ("Prefijo").AddCurrentValue(CodigoPrefijo)

next
On Thursday, August 17, 2006 6:53:21 PM Mostafa h. said:
In Form1 I've a CheckBox Control . I droped A CrystalReportViewer and ReportDocument in Form1.
I want to take a Report to show all of the Records' specified field(for e.g. :"firstname") , when I checked the CheckBoxControl . I Wrote this in btnShowReport_Click:

string query = "select * from TestReport";

sqlconn.Open();

da = new SqlDataAdapter(query, sqlconn);

SqlCommandBuilder scb = new SqlCommandBuilder(da);

da.Fill(DS.TestReport);//DS is a DataSet object .

myCrystalReport1.SetDataSource(DS);


//-----------------

ParameterField paramfield = new ParameterField();

ParameterFields paramfields = new ParameterFields();

ParameterDiscreteValue discreteval = new ParameterDiscreteValue();


paramfield.Name = "myfirstname";

discreteval.Value = "10";


paramfield.CurrentValues.Add(discreteval);

paramfields.Add(paramfield);

crystalReportViewer1.ParameterFieldInfo = paramfields;

//-----------------

crystalReportViewer1.ReportSource = myCrystalReport1;


crystalReportViewer1.Refresh();

sqlconn.Close();

and I create a parameter in report :"myfirstname" and in Formula editor , I wrote this :
if {?myfirstname}="10" then {TestReport.firstname} = {?myfirstname}
Now , I want to say :
- I want to be shown all of the record firstname field ,how can i do it in :
discreteval.Value = ???????????????????
thanks for any help .
Regards ,
On Thursday, August 24, 2006 5:08:12 AM ankur sehgal said:
hi..
I have been traying to pass a value from a textbox(let it be an id of an employ)and i want report of only that employ whose id i hav  passed in textbox at runtime..
please help me out..
thanks.
On Thursday, August 24, 2006 4:07:09 PM Imar Spaanjaars said:
Hi ankur,

Isn't that simply a matter of changing this:

myDiscreteValue.Value = "USA";

to this:

myDiscreteValue.Value = txtEmpId.Text;

Imar
On Thursday, August 31, 2006 4:56:12 PM premanshu sinha said:
hello sir,

i hv done same thing what u mentioned here but i m getting a prompting text and asks login information and after its showing whole information


i m using VS2005 an asp.net2.0
On Thursday, September 14, 2006 9:32:06 PM anja said:
QuickDocID 310 (I apologize for multiple posting of the same question)

OK. I give. This is a great article (comes close to what I'm trying to accomplish but ...) I have two remaining issues:

a. I need to manipulate two parameters (@MillDate and @OperationalArea).

b. I would like to read the value from a textbox (no problem there) and refresh the report based on the values in the text box upon button click (all this of course in a web-site).

Sounds really simple, shouldn't be hard at all, cost me the last 2 days and makes me feel very humble. Help, please?
On Friday, September 15, 2006 1:30:23 PM Anja said:
OK. Found the solution and want to post it for all other frustrated coders. If you use the crystalviewer and set your parameters in the report document and then tie the document to the viewer via report source the parameters don't seem to refresh if you change the values in the report document after the first post.

You need to use CrystalReportViewer1.ParameterFieldInfo.Clear() to actually clear the parameter values in the viewer.
On Monday, September 18, 2006 6:50:30 AM Vidhan Vijayavergiya said:
Is it feasible to work on crystal report 11 in visual basic 6. A problem that i am getting is while populating the crystal report, it is asking for the parameters. i had not found any crystal report viewer form crystal report 11. how can i do it best. can anybody help me out in this.
On Friday, October 20, 2006 4:07:31 PM Sangita Gupta said:
I am using vb6 with Crystal Report8.5 and trying to pass my Start date and end date parameter(got from here). It is not working.plz help.Thanks.
My code are here:
cn.open       'to open connection string.
CrystalReport1.ReportFileName = "C:\Audit.rpt"          'setting file name
CrystalReport1.Action = 1  
CrystalReport1.ParameterFields(0) = "startdate;" & DTPicker7.Value & ";False"                            
CrystalReport1.ParameterFields(0) = "enddate;" & DTPicker8.Value & ";False"                                          
On Saturday, October 21, 2006 6:46:46 AM Imar Spaanjaars said:
Hi Sangita,

Please post this question on a forum like the one at http://p2p.wrox.com/

A forum is a *much* better place for asking technical questions and getting fast and correct answers. Unfortunately, I don't have the time to answer each question I get on this site personally.

Thanks,

Imar
On Tuesday, October 31, 2006 8:00:18 AM Sadaqat said:
I am using  crystal XI and I want to pass to formula through progrmatically using VB.net.
On Wednesday, November 01, 2006 1:00:38 PM saravanan said:
1)i am using crystal reports 11 and asp.net 2005. how to pass the sql query through crystal reports.
2)And another one question is if i ll pass to empty values in parameter field then sql query in dont check the condition otherwise i pass the parameter then check that where condition
On Wednesday, November 01, 2006 6:31:55 PM apg said:
hi,

i'm using crystal report 8.0 and studio 2005 windows application.

i've to make a parametrized crystal report and parameter will be passed through a windows form.

The problem i'm facing is that login message comes again and again and it's not working. please help me.

Thanks in advance.
On Sunday, November 05, 2006 5:36:01 AM Mohammed Jameel said:
Hi;

I a report using Sql Stored procedure as a data source, I want to run that report from vba or vb6 and pass the parameter values from user screen by coding ?

Thanks

Mohammed Jameel
On Monday, November 13, 2006 6:58:13 AM Prathakini said:
I need to run a stored procedure which is having 5 select statements at the end only once and the result set of those 5 select for 5 individual cystal reports. Is this possible.
On Monday, November 13, 2006 11:12:38 AM ashok jangid said:
Hi friends,
       I am working in web application and i can show crystal report very well in web application but the main problem is that i want that, report only generated with selected item only which is i supplied in form means i want to filter the report by entering data in textbox on web page. I am unable to pass that kind of query for crystal report.
Please help me.
Thanking You
On Saturday, November 18, 2006 12:43:37 PM Imar Spaanjaars said:
Hi ashok,

Doesn't this article describe exactly that scenario?

I think you're better off posting this question at a forum like the one at http://p2p.wrox.com/

Cheers,

Imar
On Monday, November 27, 2006 6:35:31 AM TAQI said:
Hi All i am using vb6 Program and reports in crystal report 9 can any one help  me to pass start date and end date parameter in crystal report 9
On Wednesday, December 27, 2006 2:36:02 PM Prasanth said:
hi everybody,

i'm new to Crystal repoert can anybody help me how to use two different queries in one crystal reports

environiment details:

Application : PeopleSoft
Database : Oracle
Reporting Tool : Crystal Report

i'm generating the two queries using PS Query tool
On Wednesday, January 17, 2007 11:41:17 AM Deepak Shami said:
Hi,

Pleas help me in passing multiple dicrete values selected from a list box to one crystal parameter field.

for example:
abc is a string type crystal parameter,
in crystal selection formula, i wrote " {EMast.Proc} in {?abc}"
now i want to select multiple values from a listbox in asp.net page and then load report based on those selected values in listbox.

On Friday, February 02, 2007 7:42:09 AM miruthula said:
i tried above article,parameter is not passing to report.it shows invalid pointer.while debug this code.

CrystalReportViewer1.ReportSource = rpt
i need very urgent reply for this pbm ...please
On Friday, February 02, 2007 7:54:26 AM Imar Spaanjaars said:
Hi miruthula,

The comments in the code say this:

// Assign the Report to the report viewer.
// This method uses a strongly typed report,
// but other methods are possible as well.
myCrystalReportViewer.ReportSource = MyReportObject

This means you need to supply your own report. How you get that report (load it, create it programmatically), is up to you. See the CR help for more details.

Cheers,

Imar
On Friday, February 02, 2007 8:02:40 AM miruthula said:
Dim paramFields As New ParameterFields
        Dim paramField As New ParameterField
        Dim discreteVal As New ParameterDiscreteValue

        paramField.ParameterFieldName = "Country"
        discreteVal.Value = "USA"
        paramField.CurrentValues.Add(discreteVal)

        paramField = New ParameterField
        discreteVal.Value = "Netherlands"
        paramField.CurrentValues.Add(discreteVal)

        paramFields.Add(paramField)
        Dim rpt As New MyReport

        CrystalReportViewer1.ParameterFieldInfo = paramFields
        CrystalReportViewer1.ReportSource = rpt

ya i passed report having one parameter field country in it.but it shows invalid pointer.please help me sir.i need it.
On Friday, February 02, 2007 8:30:43 AM Imar Spaanjaars said:
Hi miruthula,

I suggest you post this on a forum like http://p2p.wrox.com.

If you do post there, be sure to provide lots more information. "it shows invalid pointer" is not enough detail to provide a solution.

Imar
On Friday, February 02, 2007 10:45:48 AM miruthula said:
hi Imar,
     i submitted my code detaily in http://p2p.wrox.com/forum.asp?FORUM_ID=109 please check it reply soon.
Topic:
.NET->CrystalReport->Passing Multiple Parameters to a Crystal Report Programmatically.
On Friday, February 02, 2007 11:26:50 AM Imar Spaanjaars said:
Hi miruthula,

I looked at the thread, but unfortunately, I don't know the answer. Hoepfully someone else does.

Cheers,

Imar
On Saturday, February 03, 2007 5:58:25 AM Aftab Mulani said:
I want to build datewise report .
when i choose two date the differnce between the date my data have to shown .
pls tell how to do in asp.net2005.
On Thursday, February 08, 2007 9:31:45 AM Rakesh Grover said:
I am facing one problem with Crystal reportXI while setting the datasource ... Can you please send me the proper solution  ?
What all the actual parametrs I have to pass ? Please reply as soon as possible.

See my java code below :

       InputStream is = new FileInputStream(xmlFile); // Path of my xml file
        int length = is.available();
        byte [ ] byteArray = new byte[length];
        is.read(byteArray, 0, length);
        ByteArray ba = new ByteArray (byteArray);
        IXMLDataSet xmlSet = new XMLDataSet ();
        xmlSet.setXMLData(ba);


       ConnectionInfos connectionInfos = new ConnectionInfos();
       IConnectionInfo connectionInfo = new ConnectionInfo ();

       PropertyBag propertyBag = new PropertyBag ();
       PropertyBag propertyBag1 = new PropertyBag ();
       propertyBag.put( "SSO Enabled", "false" );
       propertyBag.put( "Database DLL", "crdb_odbc.dll" );
       propertyBag.put(PropertyBagHelper.CONNINFO_SERVER_NAME ,"localhost" );
       propertyBag.put(PropertyBagHelper.CONNINFO_CRQE_DATABASENAME ,"Xtreme ");
        propertyBag.put(PropertyBagHelper.CONNINFO_CRQE_SERVERDESCRIPTION ,"Xtreme" );
        propertyBag.put(PropertyBagHelper.CONNINFO_CRQE_SQLDB ,"false" );
        propertyBag.put(PropertyBagHelper.CONNINFO_SSO_ENABLED ,"true" );
        propertyBag.put(PropertyBagHelper.CONNINFO_CRQE_DATABASETYPE ,"ODBC (RDO)" );
        propertyBag1.put("DSN" , "Xtreme");
        propertyBag1.put(" UseDSNProperties", "true" );
        propertyBag1.put("user" , "user");
        propertyBag1.put("password" , "password");
         propertyBag.put(PropertyBagHelper.CONNINFO_CRQE_LOGONPROPERTIES ,propertyBag1);

          connectionInfo.setAttributes(propertyBag);
          connectionInfo.setKind(ConnectionInfoKind. CRQE);            
          connectionInfo.setUserName( "user");
          connectionInfo.setPassword( "password");
          connectionInfos.add(connectionInfo);
          reportClientDoc.getDatabaseController().logonEx( "localhost" , "Xtreme" , "user", "password" );      
           reportClientDoc.getDatabaseController().setConnectionInfos(connectionInfos);
           reportClientDoc.getDatabaseController ( ).setDataSource(xmlSet);

Exception is :


com.crystaldecisions.sdk.occa.report.lib.ReportSDKLogonException : Logon failed.
Error in File C:\WINDOWS\TEMP\{FCA40381-7561-483B-978E-5B51C58AE2CB}.rpt:
Unable to connect: incorrect log on parameters .---- Error code:-2147217393 Error code name:dbLogonFailed
      at com.crystaldecisions.sdk.occa.report.lib.ReportSDKLogonException.throwReportSDKLogonException(Unknown Source)
   at com.crystaldecisions.proxy.remoteagent.r.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.dd.a(Unknown Source)
    at com.crystaldecisions.sdk.occa.report.application.DatabaseController.a(Unknown Source)
     at com.crystaldecisions.sdk.occa.report.application.DatabaseController.setDataSource(Unknown Source)
     at crystalreportdemo.CrystalReportDemoSample.createCrystalReport( CrystalReportDemoSample.java:129)
     at crystalreportdemo.CrystalReportDemoSample.main(CrystalReportDemoSample.java :249)

Pls help me to solve this issue .. I did not get any direct help from google search .
On Friday, February 16, 2007 2:50:54 AM gaurav said:
thank you
On Friday, March 16, 2007 12:28:23 PM lokesh malav said:
paramField.ParameterFieldName = "Plot_Society_Id";
        intplotSocid = Convert.ToInt16(Session["intPloteSocId"]); //Convert.ToInt16(Request.QueryString["intPloteSocId"]);
        discreteVal.Value = intplotSocid;
        paramField.CurrentValues.Add(discreteVal);

        paramFields.Add(paramField);

        paramField.ParameterFieldName = "List_scheme_code";
        List_scheme_code = Convert.ToInt16(Session["List_scheme_code"]); // Convert.ToInt16(Request.QueryString["List_scheme_code"]);
        discreteVal.Value = List_scheme_code;
        paramField.CurrentValues.Add(discreteVal);

        paramFields.Add(paramField);

        CrystalReportViewer1.ParameterFieldInfo = paramFields;      
        CrystalReportViewer1.ReportSource = Server.MapPath("CrystalReport.rpt");
        CrystalReportViewer1.DataBind();

pls tell me solution
i do that code  but Result in crystal report is unchanged

my data is same all time



On Monday, April 02, 2007 7:24:58 AM virendra said:
string query = "select * from TestReport";


sqlconn.Open();

da = new SqlDataAdapter(query, sqlconn);

SqlCommandBuilder scb = new SqlCommandBuilder(da);

da.Fill(DS.TestReport);//DS is a DataSet object .

myCrystalReport1.SetDataSource(DS);

in this one is coming that is" the dataset has no tables"
how cal i solve this plz rply soon.
On Wednesday, April 11, 2007 5:22:31 AM Subramanian.C said:
Dear Sir/Madam,

  I have 2 reports with passing parameter. it is working fine.Now, i want to create 2 subreports in one main reports so, my doubts is HOW TO WRITE CODING SUBREPORTS WITH PASSING PARAMETERS.

can you tell me anyone clearly..

Thanks and Best Regars,
Subramanian.C
On Monday, April 30, 2007 10:45:31 AM Latha said:
Hi, I actually i done crystal reports in windows apps but, i dont know how to
implement crystalreports in usind Asp.net2.0 with C#.Can you plz tel me how to implement crystalreports using  Asp.net2.0 with C#.
On Monday, April 30, 2007 11:31:56 AM Imar Spaanjaars said:
Hi Latha,

You probably want to get yourself a book about Crystal Reports, like this one: http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764557300.html

Although it targets ASP.NET 1, it shows a lot of concepts that are still applicable in .NET 2. I am sure that Amazon has more books about CR in .NET 2.

Cheers,

Imar
On Friday, May 04, 2007 5:27:55 AM ramya2bobby said:
i am able to pass only the first value and the rest could not be passed... tell me where i went wrong...and i hav one more doubt... is there any events for crystal report...please clear my doubts...
On Monday, May 07, 2007 5:53:29 AM Ansari said:
i got this error:

  Logon failed. Details: ADO Error Code: 0x Source: Microsoft OLE DB Provider for SQL Server Description: Login failed for user ''. The user is not associated with a trusted SQL Server connection. SQL State: 42000 Native Error: Error in File C:\DOCUME~1\SYS-4\ASPNET\LOCALS~1\Temp\SupplyChain {768A5CBC-4509-4E4C-B9E3-AE6E053D45E8}.rpt: Unable to connect: incorrect log on parameters.

please give me a solution.
thanks adn regards
ansari.s
On Monday, May 07, 2007 6:29:16 AM Imar Spaanjaars said:
Hi Ansari,

This error seems to be related to security, not to parameters in a CR report.

Try Google for the exact error message about the trusted connection and you'll find many useful articles.

Imar
On Monday, May 07, 2007 8:18:22 AM Dollina L. Mendonca said:
Solutions given are quit satisfactory.

I have one problem with crystal report in C#

I have created formula @SName in the crystal report and i want to pass value to it using set_formula() method.

Please mail me the solution
On Monday, May 07, 2007 5:04:00 PM Imar Spaanjaars said:
Hi Dollina,

I don't know what your set_formula() applies to, so I guess you have to look elsewhere.

Imar
On Wednesday, May 16, 2007 10:14:19 PM Manny said:
Hi There,

I am passing parameters to 3 subreports as following -

techSpprt.Subreports["TechSupport_TypeOfCalls_Graph.rpt"].RecordSelectionFormula = @"{vsrIncidentTypes_i3dvr.IncidentDate} in DateTime(" + final1 + ") to DateTime(" + final2 + ")";


techSpprt.Subreports["TechSupport_TypeOfCalls_SubReport.rpt"].RecordSelectionFormula = @"{vsrIncidentTypes_i3dvr.IncidentDate} in DateTime(" + final1 + ") to DateTime(" + final2 + ")";

techSpprt.Subreports["TechSupport_TypeOfCalls_RecCount.rpt"].RecordSelectionFormula = @"{vsrIncidentTypes_i3dvr.IncidentDate} in DateTime(" + final1 + ") to DateTime(" + final2 + ")";

Its only picking up the last parameter for last subreport. Is this the default behavior? If I comment them one by one ... it wors fine for the subreport for whcih I am passing the parameter. but If I enable 2 or 3 all at same time. It only picks up last parameter for last subreport. I am kindda frustrated. Please suggest any resolution or a way.

Manny
On Friday, June 15, 2007 3:09:50 PM dix said:
Please can somebody help me.I have several crystal reports with parameters. i wnat to be running them from VB dot net. but the problem is, when i load them the enter parameter window comes up with next and back buttons. how can i have the window show all the parameters in one windw? as it does when i refresh from crystal report designer. i wan to have all reports in one folder. please help urgently
On Sunday, June 17, 2007 7:26:03 PM yazzy said:
Please could someone help me, I am new and I am trying my first ever crystal report. The only crystal report i have is bundled with vb.net 2005 version. I have read lots of articals and followed examplews BUT i still get the Parameter entry page coming up. I have a stored procedure which had 5 variables declared. The stored procedure works!!

Thanks in advance

the code i am using is

using System;
using System.Data;
using System.Configuration;


<snip> Rest of the code cut by Imar
On Sunday, June 17, 2007 7:38:41 PM Imar Spaanjaars said:
Hi yazzy,

Please don't use my web site as a general purpose code forum. Try the Crystal Reports forum or http://p2p.wrox.com instead. It's much easier to post code and replies on those kind of sites.

Cheers,

Imar
On Thursday, August 09, 2007 4:37:11 PM Busa said:
I have similar piece of code as mentioned by Mostafa h. However my issue   the parameters I pass are not displayed where there are used in the report. I am using the following syntax in the report {?@myfirstname}

myCrystalReport1.SetDataSource(DS);
//-----------------
ParameterField paramfield = new ParameterField();
ParameterFields paramfields = new ParameterFields();
ParameterDiscreteValue discreteval = new ParameterDiscreteValue();
paramfield.Name = "myfirstname"; discreteval.Value = "10";
paramfield.CurrentValues.Add(discreteval); paramfields.Add(paramfield);
crystalReportViewer1.ParameterFieldInfo = paramfields;
//-----------------

crystalReportViewer1.ReportSource = myCrystalReport1;
crystalReportViewer1.Refresh()
On Thursday, August 23, 2007 11:50:19 AM reza hoseini said:
thank you , your code     for me   was very good,
i can paramete pass eith c#.net and crystal report.
On Thursday, October 25, 2007 12:50:24 PM tiya said:
how do i pass the selectedvalue, of the items in a checklist box control to crystal report as multiple value.
On Saturday, November 17, 2007 12:21:53 PM COMFORT PETER said:
I have created a crystal report. Am getting a prompt that I have to enter the reports parameters again on running my dotnet application. Here is the code I use:

Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load
        Dim TestingReport_Param As New TestingReport_Param
       Dim CRDoc As UserDetailReport = New UserDetailReport

        Dim pubnamereceivedtouse As New CrystalDecisions.Shared.ParameterValues
        Dim pubnamereceived As New CrystalDecisions.Shared.ParameterDiscreteValue

        Dim loginfromserver As New ClsLoginInfo
        loginfromserver = MDIform.general.Fetchlogininfo

        Dim decryptedpassword As String
        decryptedpassword = MDIform.general.Decrypt(Convert.FromBase64String(loginfromserver.userpassword))

        Dim reportPath As String = Application.StartupPath & "\UserDetailReport.rpt"

        CRDoc.Load(reportPath)

        Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
        myConnectionInfo.ServerName = loginfromserver.Servername
        myConnectionInfo.DatabaseName = loginfromserver.Databasename
        myConnectionInfo.UserID = loginfromserver.userid
        myConnectionInfo.Password = decryptedpassword

        SetDBLogonForReport(myConnectionInfo, CRDoc)

        pubnamereceived.Value = TestingReport_Param.pubnamefromformparam
        pubnamereceivedtouse.Add(pubnamereceived)

       CRDoc.DataDefinition.ParameterFields("pubname").ApplyCurrentValues(pubnamereceivedtouse)

        CrystalReportViewer1.ReportSource = CRDoc

    End Sub

Any solution to this?
On Thursday, November 29, 2007 10:29:14 AM Noman said:
i want to display report without prompting for database Login Info
and i have also create dsn connection but problem is that how to pass this dsn object to reportDocument class
how to pass connection string to rpt.Load() method??
plz help me
//code
string strconn1 = "Driver={SYBASE ASE ODBC Driver};NA=172.17.18.2,5000;Uid=habib;Pwd=007opel;";
            OdbcConnection dsn_ivr = new OdbcConnection(strconn1);
            dsn_ivr.Open();

            ConnectionInfo con = new ConnectionInfo(dsn_ivr);


            Session["agentid"] = "5005";
            ReportDocument rpt = new ReportDocument();
            
            rpt.Load(@"C:\Documents and Settings\Ufone\My Documents\Visual Studio 2005\WebSites\CrystalReportsWebSite1\mm-agt1.rpt",con );//ConfigurationSettings.AppSettings.Get("con_dsn"));
            rpt.SetParameterValue("agt_id", Session["agentid"].ToString());


            this.CrystalReportViewer1.ReportSource = rpt;
On Thursday, December 13, 2007 10:40:17 AM MS Baker said:
Hi,
I tried your code in my VB.Net project as follows

' Create parameter objects

Dim myParams As New ParameterFields
Dim myParam As New ParameterField
Dim myDiscreteValue As New ParameterDiscreteValue
Try
            With crwViewer
                Dim ReportFile As String
                Dim mReportFileStr() As String
                mReportFile = Configuration.ConfigurationSettings.AppSettings("ReportLocation") & ResolvePhysicalReportPath(pReportFile)
                .ReportSource = mReportFile

                If Not pRecordSelectionFormula Is Nothing Then
                    If pRecordSelectionFormula.Length <> 0 Then
                        ' If selection formula is specified apply it
                        .SelectionFormula = pRecordSelectionFormula
                    End If
                    mRecordSelectionFormula = pRecordSelectionFormula
                End If

                '' Setting the ParameterFieldName to the name of the parameter created in the Field Explorer
                myParam.ParameterFieldName = "TempID"

                ''Adding a value
                myDiscreteValue.Value = "ID898"

                myParam.CurrentValues.Add(myDiscreteValue)

                '' Adding param object to params collection
                myParams.Add(myParam)

                '' Assign the params collection to the report viewer
                .ParameterFieldInfo = myParams

        End With
   crwViewer.RefreshReport()
   crwViewer.Show()
   Me.ShowDialog()
Catch ex As Exception
   MsgBox(ex.Message)
End Try

I still am being propted for a default value for the parameter when i call the report. Kindly help me on this one.
On Thursday, December 13, 2007 11:41:46 AM shimjith said:
hai,

    I am using Crystal Report 10 , SqlExpress 9, and VS2005.
i am Usig C# coding.
When I passing Parameter to Crystal Report default Parameter window is Coming And Also Asking For Password For CryStal Report in Another Window. How Can Avoid these Two.  


My coding are given Below


private void TradingProfitLoss()
        {
            frmRpt = new frmRvewr();
            crReportDocument = new ReportDocument();
            Subreports sb ;
            ReportDocument crSub = new ReportDocument();
            myParams = new ParameterFields();
            crReportDocument.FileName = path + "TDPL.rpt";

           myParam = new ParameterField();
            myDiscreteValue = new ParameterDiscreteValue();
            myParam.ParameterFieldName = "Date";
            myParam.HasCurrentValue = true;
            myDiscreteValue.Value = Cm.encodeDate            (dtpFrom.Value.ToString  ("dd/MM/yyyy"));
            myParam.CurrentValues.Add(myDiscreteValue);
            myParams.Add(myParam);

           ShowReport();
            
            frmRpt.Rptview.ParameterFieldInfo = myParams;
            frmRpt.Rptview.ReportSource = crSub;
            frmRpt.Rptview.ReportSource = crReportDocument;
            frmRpt.Rptview.RefreshReport();
        }


public void ShowReport()
        {
            ERPProject.General.ConfiCreation config = new           ERPProject.General.ConfiCreation();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = config.GetCnnInfo();
            Tables CrTables;
            crReportDocument.Load(crReportDocument.FileName);
            CrTables = crReportDocument.Database.Tables;
            foreach (Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }
            frmRpt.Rptview.ReportSource = crReportDocument;
            frmRpt.Show();
        }
          

I am waiting For Your Reply Please Help Me
On Thursday, December 13, 2007 12:23:18 PM Imar Spaanjaars said:
Hi there,

Please use a technical support forum for these kinds of questions: p2p.wrox.com

Imar
On Monday, January 07, 2008 11:05:54 AM ujjwal said:
how can i pass multiple values to a parameter in crystal report through vb.net