我已将存储过程参数化为 Crystal Report 的源。我试图从 Code C# 后面传递它们。
我提到了很多主题,但仍然遗漏了一些东西,并且出现了错误:
Failed to open a rowset.
Details:
ADO Error Code: 0x
Source: Microsoft SQL Native Client
Description: Procedure 'SP_GetProductsbySales' expects parameter '@top', which was not supplied.
SQL State: 42000
Native Error: Failed to open a rowset.
Error in File C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\TopSelling_Report {B8B4EAE6-D01E-4D18-9003-23A047F9DD5B}.rpt: Failed to open a rowset
这是我的代码:
private void ConfigureCrystalReports()
{
rpt = new ReportDocument();
string reportPath = Server.MapPath("TopSelling_Report.rpt");
CrystalReportViewer1.ParameterFieldInfo.Clear();
ParameterFields param = CrystalReportViewer1.ParameterFieldInfo;
ParameterField top = new ParameterField();
top.Name = "@top";
ParameterDiscreteValue top_val = new ParameterDiscreteValue();
top_val.Value = 100;
top.CurrentValues.Add(top_val);
ParameterField all = new ParameterField();
all.Name = "@all";
ParameterDiscreteValue all_val = new ParameterDiscreteValue();
all_val.Value = false;
all.CurrentValues.Add(all_val);
param.Add(top);
param.Add(all);
CrystalReportViewer1.ParameterFieldInfo = param;
rpt.Load(reportPath);
rpt.SetParameterValue(0, Convert.ToInt32(50));
rpt.SetParameterValue(1, Convert.ToBoolean(false));
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "xxxx";
connectionInfo.DatabaseName = "xxxxx";
connectionInfo.UserID = "xxx";
connectionInfo.Password = "xxxx";
SetDBLogonForReport(connectionInfo, rpt);
CrystalReportViewer1.ReportSource = rpt;
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
如您所见,我尝试以两种方式传递参数,但仍然出现错误。我发现了特定问题,如果我删除SetDBLogonForReport()方法,那么它工作正常。所以,如果我删除自动登录,那么它工作正常,但如果我保持原样或修改那个的代码,那么它会给出高于错误。
我尝试用 SetDatabaseLogon() 方法替换我的代码,但它仍然给了我不期望的登录提示。
我正在使用 Visual Studio 2005。感谢您的帮助。谢谢。