title: Accessing the result set of a stored procedure, executed using SqlDataSource.Select
body: <p>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.</p>
  
  <p>My code currently correctly obtains their ID, adds it as a parameter to my stored procedure and executes the procedure;</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>However, when I try to access the results I get the following error:</p>
  
  <pre><code>System.NullReferenceException: Object reference not set to an instance of an object.
  </code></pre>
  
  <p>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.</p>
  
  <p>How do I access this result so I can bind it to my fields?</p>
  
  <p><em>(I am working in ASP.NET 3.5 in Visual Studio 2008, with SQL Server 2008.)</em></p>