我有了這個調用方法:獲取的SqlDataAdapter和SqlCommand的困惑
public string RunReportSteps(int _reportKey) {
DataTable fStepsTable;
fStepsTable = GetStepsTable("xxx.console.pr_xxx");
return (string)fStepsTable.Rows[1][3];
}
它調用此私有方法:
private DataTable GetStepsTable(string procName) {
var connectionString = ConfigurationManager.ConnectionStrings["xxx"].ConnectionString;
using(var conn = new SqlConnection(connectionString))
using(var adapt = new SqlDataAdapter())
using(var cmd = new SqlCommand(procName, conn)) {
conn.Open();
SqlParameter p = new SqlParameter("@ReportKey", this.ReportKey);
p.Direction = ParameterDirection.Input;
cmd.Parameters.Add(p);
adapt.SelectCommand = cmd;
DataSet mySet = new DataSet();
adapt.Fill(mySet); //<<<<<<<<<<<<<<<<<<<errors here
return mySet.Tables[0];
}
}
爲什麼會收到以下錯誤消息?
過程或函數'pr_xxx'預計未提供參數 '@ReportKey'。
我不知道這是否是問題的根源,但你不應該指定要使用存儲過程? –