如何传递参数 ( 积分: 50 )

  • 主题发起人 菲菲123
  • 开始时间

菲菲123

Unregistered / Unconfirmed
GUEST, unregistred user!
我Catalog类中创建了
public SqlDataReader GetCategoriesInDepartment(string departmentID)
{
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand("GetCategoriesInDepartment",conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@DepartmentID",SqlDbType.Int,4).Value=departmentID;
//cmd.Parameters["@DepartmentID"].Value = departmentID;
try
{
conn.Open();
SqlDataReader thisdatareader =cmd.ExecuteReader(CommandBehavior.CloseConnection);
return thisdatareader;
}
catch (Exception e)
{
conn.Close();
throw e;
}
}
在控件中调用
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string departmentId = Request.QueryString["DepartmentID"];
//int departmentID =int.Parse(departmentId);
Catalog catalog = new Catalog();
if (departmentId!="")
{
string listIndex = Request.Params["CategoryIndex"];
if(listIndex=="")
List.SelectedIndex =int.Parse(listIndex);
List.DataSource =catalog.GetCategoriesInDepartment(departmentId);
List.DataBind();
}
}
过程 'GetCategoriesInDepartment' 需要参数 '@DepartmentID',但未提供该参数。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 过程 'GetCategoriesInDepartment' 需要参数 '@DepartmentID',但未提供该参数。
源错误:

行 81: {
行 82: conn.Close();
行 83: throw e;
行 84: }
行 85: }
 

Similar threads

回复
1
查看
500
huangcunwei
H
回复
3
查看
390
菲菲123
顶部