0
我想从我的代码运行sp。 sp名称存储在数据库中。我通过字典传递参数。这段代码是我在Windows服务中托管的wcf服务方法之一。我的代码是:从我的c#代码调用存储过程的问题
private DataSet RunReport(int id, ParameterDictionary parametersDic)
{
DataSet result = new DataSet();
try
{
DataSet report = GetReportDataset(id);
if (report.Tables[0].Rows.Count > 0)
{
string reportType = GetReportTypeDataset(Convert.ToInt32(report.Tables[0].Rows[0]["ReportTypeID"]));
if (reportType != ReportType.StoredProcedure.ToString())
{
throw new Exception("your report is not a sp report.");
}
using (DbCommand paramCommand = DatabaseManager.Database.GetStoredProcCommand(report.Tables[0].Rows[0]["SQLQuery"].ToString()))
{
foreach (var parameter in parametersDic)
{
DatabaseManager.Database.SetParameterValue(paramCommand, parameter.Key, parameter.Value);
}
result = DatabaseManager.Database.ExecuteDataSet(paramCommand);
result.AcceptChanges();
}
}
}
catch (Exception ex)
{
throw ex;
}
return result;
}
当我运行这段代码下面的错误计提坏账:
一个的SqlParameter带参数名称“ID”不受此 SqlParameterCollection遏制。
另外,当我通过win表单调用这个方法时,每件事都可以。 有什么问题?
您可以使用此方法运行所需的每个sp。 –
GetStoredProcCommand是企业库方法之一。 http://msdn.microsoft.com/en-us/library/bb748721%28v=pandp.31%29.aspx –