Can you tell me what are the steps to pass parameters to crystal reports 13 in C# win form..
my code:
//getting and set dataset to report
string sql = "select * from dbo.Trading_Order";
DataRetriever dr = new DataRetriever();
dr.getValueFromCustomer(sql);
DataTable dtSum = dr.getDataTable();
dsMyReprt k = new dsMyReprt();
k.Tables.Remove("dtMyTable");
dtSum.TableName = "dtMyTable";
k.Tables.Add(dtSum);
CrystalReport1 myDataReport = new CrystalReport1();
//pass parameter
ParameterFields paramFields = new ParameterFields();
// ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "@DTotal";
paramDiscreteValue.Value = tot;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField();
paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "@name";
paramDiscreteValue.Value = name;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
crystalReportViewer1.ParameterFieldInfo = paramFields;
myDataReport.SetDataSource(k);
crystalReportViewer1.ReportSource = myDataReport;
getting and set dataset part is working but passing parameters part is not working
I got big headaches with that for weeks... I have to precise that I set a sql query in the Crystal Reports Designer. Thus, I didn't use a dataTable like you did, so you have to consider that.
Well, @campagnolo_1 suggested you :
This is the short and sweet solution. But, following this, you have to make sure you have created
MyParameter1
,MyParameter2
andMyParameter3
of type String in the Crystal Reports Designer.It's important to mention that you have to Load the report before setting your parameters with
SetParameterValue
.If your parameter's name is
MyParameter1
, then don't add a@
in front like this :myDataReport.SetParameterValue("@MyParameter1", "Hello1"); // Your program will crash.
If you got
The parameter is incorrect
then you should make sure the type of parameter value you gave is exactly the same as the parameter type. For example, if you have a parameterStartDate
as type Date, then make sure the value you'll give is of type Date and has the right date format.Also, you have talked about dynamic or static field. In your case, I think you enter values manually, then this is static field.
Hope this helps you.
Why not try it this way and save yourself some coding?
You probably have figured the solution by now. But this may help. You enter values that are passed as a parameter.
http://www.codeproject.com/Tips/753879/Automatically-Setting-a-Parameter-from-a-Csharp-Va