Crystal Reports - how to pass parameter? - crystal-reports

I would like to pass a parameter to my report and put the report into my project.
I want to pass a user id as parameter to the report.
The id will be different each time.
Can someone help me on this topic how to pass the parameter.
Here is my code so far:
CrystalReportViewer1.Visible = True
Dim rDoc As New ReportDocument()
' Crystal Report Name
rDoc.Load(Server.MapPath("Sucess.rpt"))
' Your .rpt file path
'set dataset to the report viewer.
CrystalReportViewer1.ReportSource = rDoc

You can try something like this:
string ponumber;
string receiptno;
ponumber = TextBox1.Text;
CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();
CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.EnableParameterPrompt = false;
CrystalReportSource1.Report.FileName = "Report3.rpt";
CrystalReportSource1.EnableCaching = false;
CrystalReportSource1.ReportDocument.SetParameterValue(0, ponumber);
CrystalReportSource1.ReportDocument.SetParameterValue(1, receiptno);

Related

I can't display parameter value in report header in crystal reports

I'm developing a small application in c# and I'm using Crystal Reports for reporting. I want to display parameter values in report header but I can't. How can i display parameter values in report header?
ClassParams.EMANET_KITAP_ID = txtKitapID.Text;
ParameterFields From = new ParameterFields();
ParameterField KID = new ParameterField();
KID.Name = "EMANET_KITAP_ID";
ParameterDiscreteValue val = new ParameterDiscreteValue();
val.Value = ClassParams.EMANET_KITAP_ID;
KID.CurrentValues.Add(val);
From.Add(KID);
crystalReportViewer1.ParameterFieldInfo = From;
class ClassParams
{
public static string KID;
public static string EMANET_KITAP_ID
{
get { return KID; }
set { KID = value; }
}
}
Most likely, you have a multi-value parameter.
Since such a parameter stores the values as an array, you need to "flatten" the array.
If it's a String parameter, you can simply create a formula like this:
Join({?yourStringParameter}, ', ' );
If the data type is not string, loop through the array and concatenate the values to a string variable.

I can't display any result in crystal report

i'm developing a web app and I can't display any result to my crystal report. i don't know what is wrong in my code. please help.
Dim cnn As SqlConnection
Dim connectionString As String
Dim sql As String
connectionString = "data source=SERVERNAME; _
initial catalog=crystaldb;user id=sa;password=PASSWORD;"
cnn = New SqlConnection(connectionString)
cnn.Open()
sql = "SELECT * FROM Grades
Dim dscmd As New SqlDataAdapter(sql, cnn)
Dim ds As New DataSet1
dscmd.Fill(ds, "Grades")
objRpt.SetDataSource(ds.Tables(1))
CrystalReportViewer1.ReportSource = objRpt
CrystalReportViewer1.RefreshReport()

Parameter to Crystal Report

i created a #Month as parameter name in crystal report and just insert to the report header section.
When i run the report always it asks the parameter by showing one box. How i pass through code. My existing code is below
MyReport rpt = new MyReport();
var srcData = ; //here i added my LINQ statement to select the data
rpt.SetDataSource(srcData);
ParameterDiscreteValue pdValue = new ParameterDiscreteValue();
pdValue.Value = combo2.SelectedValue;
rpt.ParameterFields["#Month"].CurrentValues.Add(pdValue);
this.ReportViewer1.ReportSource = rpt;
this.ReportViewer1.RefreshReport();
Where i did the mistake?
Hi I solved by just removing RefershReport() method of crystalreportviewer
I find from : http://www.it-sideways.com/2011/10/how-to-disable-parameter-prompt-for.html
If it's not working it suggests a typo or something. Try analyzing rpt.ParameterFields (set a breakpoint and watch). Have you got the parameter name correct? Data type?
I had trouble with adding parameters as well. Here's an example of what I got working:
string ponumber = Request.QueryString["ponumber"].ToString();
string receiptno = Request.QueryString["receiptno"].ToString();
// Put Away Report
CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();
CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.EnableParameterPrompt = false;
CrystalReportSource1.Report.FileName = "Report3.rpt";
CrystalReportSource1.EnableCaching = false;
// This will set the values of my two parameters in the report
CrystalReportSource1.ReportDocument.SetParameterValue(0, ponumber);
CrystalReportSource1.ReportDocument.SetParameterValue(1, receiptno);
TableLogOnInfo logOnInfo = new TableLogOnInfo();
logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["WarehouseReportServerName"];
logOnInfo.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["WarehouseReportDatabaseName"];
logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings["WarehouseReportUserID"];
logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings["WarehouseReportPassword"];
TableLogOnInfos infos = new TableLogOnInfos();
infos.Add(logOnInfo);
CrystalReportViewer1.LogOnInfo = infos;
maindiv.Controls.Add(CrystalReportSource1);
maindiv.Controls.Add(CrystalReportViewer1);
CrystalReportViewer1.DataBind();

Print the date range on the report

I have a date range for a report from a selector. How can I print that range on the report header? I am inside a Crystal Report - not from code. I have a select expert using a IsBetween on a date field. The form prints everything fine. I just want to display the date range. I have tried the OnFirstRecord and OnLastRecord and WhilePrintingRecord to populate a string within a function - it just shows up as blank in the report.
// {#range}
// note case of format string
ToText(Minimum({?date_range}),"MM/dd/yyyy") + " - " + ToText(Maximum({?date_range}),"MM/dd/yyyy")
Add one or two Parameter in crystal report as per your requirement and then assign your date range to that parameters.
ParameterFields paramFields = new ParameterFields();
// ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "#Date1";
paramDiscreteValue.Value = TextBox1.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField(); // <-- This line is added
paramDiscreteValue = new ParameterDiscreteValue(); // <-- This line is added
paramField.Name = "#Date2";
paramDiscreteValue.Value = TextBox2.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
I found the NthSmallest and NthLargest functions - works perfectly now!

How to textbox value as a parameter in crystal report?

How to pass textbox values as parameter in crystal report in asp.net C#?
I want example which shows steps to passparamter
I have tried many examples but no output..
I want as in below link
http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-string-parameter.htm
But no data is displaying
Pls help
try this code
ReportDocument reportDocument = new ReportDocument();
ParameterFields paramFields = new ParameterFields();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "#CustomerName";
paramDiscreteValue.Value = TextBox1.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
reportDocument.Load(Server.MapPath("CrystalReport.rpt"));
CrystalReportViewer1.ReportSource = reportDocument;
I hope this will help:
ReportDocument cryReportDocument = .......;
cryReportDocument.SetDatabaseLogon("userName", "password");
cryReportDocument.SetParameterValue("parameterName", yourTextBoxName.Text);
CrystalReportViewer1.ReportSource = cryReportDocument;