我面临的问题是,脚本运行时似乎不考虑参数值。我不明白的是,Debug.Print()
方法显示正确的值,但是Access db中的存储过程未按该值选择,而是返回SELECT语句的结果,而没有对传递的参数值的任何限制。怎么了 ?
该脚本应该填充Winforms应用程序的datagridview。
private void pbSearchDepartment_Click(object sender, EventArgs e)
{
using(OleDbCommand comDeptTotals=conAcc.CreateCommand())
{
OleDbDataAdapter da = new OleDbDataAdapter();
DataTable dt = new DataTable();
comDeptTotals.CommandText = "sp_ShowDepartmentTotals";
comDeptTotals.CommandType = CommandType.StoredProcedure;
Debug.Print(cbDepartments.SelectedItem.ToString());
comDeptTotals.Parameters.AddWithValue("Area", cbDepartments.SelectedItem);
conAcc.Open();
da.SelectCommand = comDeptTotals;
da.SelectCommand.ExecuteNonQuery();
da.Fill(dt);
Debug.Print(dt.Rows.Count.ToString());
dgv_NAV_TOTALS.DataSource = dt.DefaultView;
}
}
存储过程的定义是:参数区域文本(255);
选择...从...通过...分组 ...HAVING(CC_AREA_MAPPING.Area)= [Area]);
我认为参数名称前面的@无效。
我将SP更改为:
参数@区域文本(255);
选择...从...通过...分组 ...HAVING(CC_AREA_MAPPING.Area)= @ Area);