title: Stuck on SqlDataReader.GetValues Method
body: <p>I am making a call to a SQL stored procedure which is returning a small table of users and their bosses. What I would like to do is compare this information against a variable in a different part of my application to enable/disbale editing of a GridView row. To accomplish this, it seems that the <code>GetValues</code> method would return what I need, which is the entire dataset the stored procedure is returning. My thikning is that once I have that data in my app, I could load that dataset into an array, and loop through it to do what I need to do.</p>
  
  <p>The problem is this. In my code below I am getting the error </p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'int' to 'object'</p>
  </blockquote>
  
  <p>When I look at the <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getvalues%28v=vs.110%29.aspx" rel="nofollow">documentation</a> on this method, the return value is an <code>int</code>.</p>
  
  <p>My question is, since the stored procedure contains string data (user and boss names), why is the <code>GetValues</code> mehtod returning an <code>int</code>? How is my actual data represented as a number And how do I get my data into an string based array?</p>
  
  <p>I've been looking at many examples and information on the internet, this seems to be a common problem new people have. I'm just not understanding or getting it, and I'm not making any progress. Any help is greatly appreciated!</p>
  
  <pre><code>    public Object[] GetDeptAppData()
      {
          Object[] myObject;
          string sp_deptapp, sp_status, sp_supervisor;
  
          //execute stored procedure to get data from database
          SqlConnection sqlConnection = new SqlConnection("Data Source=MyServer;Initial Catalog=MyCatalog;Persist Security Info=True;User ID=MyUser;Password=MyPassword");
          SqlCommand cmd = new SqlCommand();
          SqlDataReader reader;
  
          cmd.CommandText = "SP_Admin_DeptApp_Load";
          cmd.CommandType = CommandType.StoredProcedure;
  
          cmd.Connection = sqlConnection;
          sqlConnection.Open();
          reader = cmd.ExecuteReader();
  
          if (reader.HasRows == true)
          {
              //sp_deptapp = reader.GetValue(0).ToString();
              //sp_status = reader.GetValue(1).ToString();
              //sp_supervisor = reader.GetValue(2).ToString();
  
              myObject = reader.GetValues(myObject);
          }
          else
          {
              //nothing in reader, throw exception
          }
          sqlConnection.Close();
  
          return myObject;
      }
  </code></pre>