Pass parameter value from mvc controller to crystal reports

0

Good day.

It may be a noob question but ow do you pass a parameter from controller to crystal reports? I am kinda new when it comes to crystal reports.

Controller

ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(Server.MapPath("~/Reports"), "Mtop.rpt"));
SqlConnection cn = new SqlConnection("Data Source=test.tayabas.gov.ph;initial catalog=iVehicles;User ID=sa;Password=TEST@dm!n!@#$%;MultipleActiveResultSets=True;Application Name=EntityFramework;");
SqlCommand cmd = new SqlCommand("sp_vwFranchiseList");
SqlDataAdapter sda = new SqlDataAdapter(cmd);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@franchiseid", franchiseid);
rd.SetParameterValue("@Name", Tname);
rd.SetParameterValue("@Position", TPosition);

cmd.Connection = cn;
sda.SelectCommand = cmd;

I have a crystal report Mtop.rpt. Inside it I created two new parameters named, Name and Position. But when I try the code above, I receive an error

Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))

What am I doing wrong here? Is there an easier way to pass a value from controller to crystal reports?

Thanks in advance.

crystal-reports
asked on Stack Overflow Sep 4, 2018 by Mace Munch

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0