I'm programming a webpage in ASP.NET which displays a list of students not listed as participants in something, and upon clicking a student name shows you a brief summary of their details, so the user can ensure they're selecting the right person.
My code currently correctly obtains their ID, adds it as a parameter to my stored procedure and executes the procedure;
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);
}
However, when I try to access the results I get the following error:
System.NullReferenceException: Object reference not set to an instance of an object.
Upon debugging, there don't seem to be any results returned... but when running just the stored procedure in SQL Server with the same data, it does return a single row, as expected.
How do I access this result so I can bind it to my fields?
(I am working in ASP.NET 3.5 in Visual Studio 2008, with SQL Server 2008.)