title: How to read data table from SQL Server stored procedure
body: <p>I have this SQL Server stored procedure:</p>
  
  <pre><code>    SET NOCOUNT ON
      EXECUTE sp_configure 'Show Advanced Options', 1
      RECONFIGURE
      EXECUTE sp_configure 'Ad Hoc Distributed Queries', 1
      RECONFIGURE
  
      SELECT UserName, LoggedState, InteractionId, InteractionType    --&lt;-- The columns required.
      FROM 
      OPENROWSET('SQLNCLI'
              ,'Server=USER-PC\SQLEXPRESS;Trusted_Connection=yes;database=XXX'
              ,'EXECUTE dbo.[XXX]')
  </code></pre>
  
  <p>When I execute it in SQL Server Management Studio, I got this result:</p>
  
  <p><img src="https://i.stack.imgur.com/r5Xkp.png" alt="enter image description here"></p>
  
  <h3>My question</h3>
  
  <p>I need to read the data from the table.</p>
  
  <h3>My problem</h3>
  
  <p>This data is not in output parameters. That is why I couldn't read them.</p>
  
  <h3>What I have tried </h3>
  
  <pre><code>string vmpgraph = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
  SqlConnection Graphsqlcon = new SqlConnection(vmpgraph);
  
  SqlCommand GraphCmd = new SqlCommand("storedProcedureName", Graphsqlcon);
  
  SqlParameter tdate = new SqlParameter();
  GraphCmd.CommandType = CommandType.StoredProcedure; ;
  SqlDataAdapter DAGraph = new SqlDataAdapter(GraphCmd);
  
  DataSet DSGraph = new DataSet();
  DSGraph.Clear();
  
  DAGraph.Fill(DSGraph);
  
  DataTable DTgraph = new DataTable();
  DTgraph = DSGraph.Tables[0];
  </code></pre>
  
  <p>Is this correct? If not what should I do please?</p>
  
  <p>I couldn't test my code on a real database because I don't have the database yet.</p>