title: Get Query Results From Stored Procedure
body: <p>I am working on a program in VB.Net that interfaces with a database using LINQ.  Right now I am attempting to grab data from the following stored procedure on the database:</p>
  <pre><code>CREATE PROCEDURE dbo.GetTableColumn(
      @ColName VARCHAR(MAX),
      @TblName VARCHAR(MAX),
      @Result  BIT OUT
  ) AS
  BEGIN
      IF (EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TblName AND COLUMN_NAME = @ColName))
          BEGIN
              DECLARE @SQL VARCHAR(MAX)
              SET @SQL = 'SELECT ' + @ColName + ' FROM ' + @TblName
              EXEC (@SQL)
              SET @Result = 1
          END
      ELSE
          SET @RESULT = 0
      RETURN @Result
  END
  </code></pre>
  <p>The goal of the procedure, is that I can send a column name, and table name as variables, and if the column exists within the table the data from the table is returned.</p>
  <p>I have added the procedure to my DataLinqContext, and this is the code that references the procedure:</p>
  <pre><code>Public Function GetTableColumn(ByVal col As String, ByVal table As String) As AutoCompleteStringCollection
      GetTableColumn = New AutoCompleteStringCollection
      Using dbContext As New Customer_LINQDataContext
          Dim result As Boolean
          Dim query = dbContext.GetTableColumn(col, table, result)
          MessageBox.Show(query.ToString())
      End Using
  End Function
  </code></pre>
  <p>Now I put in the Message Box dialogue to test the output data.  However every time the method runs, the result is always <code>1</code> or <code>0</code>.  I can never get the actual data I am trying to query for.</p>
  <p>So what am I doing wrong here, and how do I fix it?</p>
  <p>EDIT: I asked over on the Database Admin Stack Exchange to see if anyone there could offer any help.  I got the following answer that can hopefully help, but I am still unsure how to fix the problem.</p>
  <blockquote>
  <p>Your code is obtaining the result of the RETURN @result at the end of the stored proc. The results you want are being passed out of the stored procedure as a ResultSet. You need to use a DataReader object to see the rows.</p>
  <p>I'm not sure how to do that using Linq. You'll hopefully get a better answer on your StackOverflow question.</p>
  </blockquote>