Crystal reports 将参数值从mvc控制器传递到crystal reports

Crystal reports 将参数值从mvc控制器传递到crystal reports,crystal-reports,Crystal Reports,你好 这可能是一个noob问题,但如何将参数从控制器传递到crystal reports?说到crystal reports,我是个新手 控制器 ReportDocument rd = new ReportDocument(); rd.Load(Path.Combine(Server.MapPath("~/Reports"), "Mtop.rpt")); SqlConnection cn = new SqlConnection("Data Source=test.tayabas.gov.ph;i

你好

这可能是一个noob问题,但如何将参数从控制器传递到crystal reports?说到crystal reports,我是个新手

控制器

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;
我有一份水晶报告
Mtop.rpt
。在它里面我创建了两个新参数,
Name
Position
。但是当我尝试上面的代码时,我收到一个错误

无效索引。(HRESULT的例外:0x8002000B(显示索引))

我做错了什么?是否有更简单的方法将值从控制器传递到crystal reports


提前感谢。

请尝试不使用“@”:rd.SetParameterValue(“Name”,Tname);rd.SetParameterValue(“位置”,t位置)@赫林格试过了,先生。仍不工作请在中建议的SetParameterValue之前尝试SetDataSource。如果它不能解决问题,请检查该帖子中的详细信息,并与您的代码进行比较。检查您是否也在传递null。@确定。我设法使它工作,但没有添加更多的参数。我只是在存储过程中添加了一个新变量,然后将这些值放在控制器的一个变量中。然后我使用cmd.Parameters.AddWithValue来添加值,然后在我的crystal报告中得到它。因为只有一个值被发布到我的报告中,所以在发布多个值时不必担心。