Passing Multiple Parameters To Crystal Report
I'm working on Visual Studio 2008 and SQL Server 2008, language C# I want to pass multiple parameters to Crystal Report in ASP.NET. I have two parameters @accountnumber and @custom
Solution 1:
You must use new keyword before assigning new values for paramField1
paramField1.Name = "@account_number";
paramDiscreteValue1.Value = accountnumber;
paramField1.CurrentValues.Add(paramDiscreteValue1);
paramFields1.Add(paramField1);
//Here is the missing code
paramField1 = newParameterField();
paramField1.Name = "@customer_id";
paramDiscreteValue1.Value = customerID;
paramField1.CurrentValues.Add(paramDiscreteValue1);
paramFields1.Add(paramField1);
Solution 2:
If the above code doesn't help you, follow the instructions below:
Go to CrystalReportSource properties -> Report properties -> Paratemers properties -> Add new parameter
And there you go. You must name the parameter as @account_number and give it a ControlID
Solution 3:
This is what I did in my code
CrystalReportViewer1.RefreshReport();
StringssCustomer= Session["ssCustomer"].ToString();
stringstrconstring= ConfigurationManager.ConnectionStrings["ONLINE_BANKING2_ConnectionString"].ConnectionString;
string sqlquery2;
sqlquery2 = "SELECT [account_number],[customer_id] from customer_details where customer_id = '" + ssCustomer + "'";
SqlConnectionmycon2=newSqlConnection(strconstring);
SqlCommandcmd=newSqlCommand(sqlquery2, mycon2);
mycon2.Open();
SqlDataReadermyreader= cmd.ExecuteReader();
myreader.Read();
stringaccountnumber= myreader["account_number"].ToString();
stringcustomerID= myreader["customer_id"].ToString();
myreader.Close();
mycon2.Close();
ParameterDiscreteValue objDiscreteValue;
ParameterField objParameterField;
//specify all the database Login details
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = "CJ-PC";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = "sa";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = "123";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = "online_banking2";
//Set value for first parameter
objDiscreteValue = newParameterDiscreteValue();
objDiscreteValue.Value = accountnumber;
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@account_number"];
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@customer_id"];
objDiscreteValue = newParameterDiscreteValue();
objDiscreteValue.Value = customerID;
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
Solution 4:
You can pass values to various parameters in Crystal Reports following this way.
voidSetParameterValues()
{
crReport report = new crReport();
report.SetParameterValue("parameterName1","parameterValue1");
report.SetParameterValue("parameterName2","parameterValue2");
}
Post a Comment for "Passing Multiple Parameters To Crystal Report"