C# 程序或功能';程序重命名';应为参数';日期参数';,这是没有提供的
我正在使用Crystal Report并指定一个以参数作为数据源的过程。我得到了这个错误: 错误: 过程或函数“sp_sale_report”需要未提供的参数“@SDate” 代码:C# 程序或功能';程序重命名';应为参数';日期参数';,这是没有提供的,c#,sql-server,stored-procedures,crystal-reports,C#,Sql Server,Stored Procedures,Crystal Reports,我正在使用Crystal Report并指定一个以参数作为数据源的过程。我得到了这个错误: 错误: 过程或函数“sp_sale_report”需要未提供的参数“@SDate” 代码: ReportDocument rprt = new ReportDocument(); rprt.Load(@"C:\Users\Zia Khan\Documents\Visual Studio 2015\Projects\lol\lol\Report\CrystalReport2.rpt"); SqlComm
ReportDocument rprt = new ReportDocument();
rprt.Load(@"C:\Users\Zia Khan\Documents\Visual Studio 2015\Projects\lol\lol\Report\CrystalReport2.rpt");
SqlCommand cmd = new SqlCommand("sp_Sale_Report", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SaleID", dateTimePicker1.Value.ToShortDateString());
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "Data_Table1");
rprt.SetDataSource(ds);
crystalReportViewer1.ReportSource = rprt;
您只传递参数
@SaleID
。它应该是@SDate
更改为:
cmd.Parameters.AddWithValue("@SDate", dateTimePicker1.Value.ToShortDateString());
否。您仅将参数名称作为SaleID传递。它应该是SDate,对吗?如果您只有一个参数,并且它的SDate意味着将SaleID更改为SDate。如果SaleID作为参数意味着,请为SDate.Side添加一个新的cmd.parameters注意:您不应该在存储过程中使用
sp\uu
前缀。微软已经这样做了,而且你确实有可能在将来的某个时候发生名称冲突。最好只是简单地避免使用sp.
并使用其他东西作为前缀,或者根本不使用前缀!您应该签出并停止使用.AddWithValue()
-这可能会导致意外的结果。。。