【发布时间】:2010-07-21 12:44:52
【问题描述】:
我正在 ASP.NET 中编写一个网页,该网页显示未列为参与者的学生列表,单击学生姓名后会显示他们详细信息的简要摘要,因此用户可以确保他们正在选择对的人。
我的代码当前正确获取了它们的 ID,将其作为参数添加到我的存储过程中并执行该过程;
protected void LinkButton_OnClick(object sender, EventArgs e)
{
LinkButton l = (LinkButton)sender;
HiddenField hfv = (HiddenField)l.Parent.FindControl("hfAdmissionNumber");
SqlDataSource2.SelectParameters.Clear();
SqlDataSource2.DataSourceMode = SqlDataSourceMode.DataReader;
SqlDataSource2.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
Parameter hfcParam = new Parameter();
hfcParam.Type = TypeCode.Int32;
hfcParam.DefaultValue = hfv.Value;
hfcParam.Name = "@AdmissionNumber";
hfcParam.Direction = System.Data.ParameterDirection.Input;
SqlDataSource2.SelectParameters.Insert(0, hfcParam);
System.Data.DataView dv = (System.Data.DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
}
但是,当我尝试访问结果时,出现以下错误:
System.NullReferenceException: Object reference not set to an instance of an object.
在调试时,似乎没有返回任何结果...但是当仅在 SQL Server 中运行具有相同数据的存储过程时,它确实返回了一行,正如预期的那样。
如何访问此结果以便将其绑定到我的字段?
(我在 Visual Studio 2008 中使用 ASP.NET 3.5,使用 SQL Server 2008。)
【问题讨论】:
标签: c# asp.net sql-server stored-procedures sqldatasource