title: Is there a way to get Select result from SQL Server 2008 with VB.Net without count?
body: <p>I'm trying to develop a tool to automatically update a database from a certain version to another where I have to run a bunch of scripts.</p>
  
  <p>I can get the tool to run the script and can get the results from it. Now I'm trying to get the "Messages" window. I'm testing with simple scripts with selects only.</p>
  
  <p>If I run the following query I get, the "Invalid object name 'tableDoesNotExist'." error</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT * FROM tableDoesNotExist
  </code></pre>
  
  <p>But if I run a working query I can't get the "(1 row(s) affected)" message</p>
  
  <p>Here is the code I'm testing</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub Execute_Query(ByVal fileInfo As BScript, X As SqlClient.SqlConnection)
      Dim objRead As New StreamReader(fileInfo.path)
      Dim commandobj As New SqlCommand()
  
      commandobj.CommandText = objRead.ReadToEnd()
      commandobj.Connection = X
  
      AddHandler X.InfoMessage, New SqlInfoMessageEventHandler(AddressOf InfoMessageHandler)
      Try
          MessageBox.Show(Convert.ToString(commandobj.ExecuteScalar()))
      Catch ex As Exception
          MessageBox.Show(ex.Message)
      End Try
  End Sub
  </code></pre>
  
  <p>Is there any property in the <code>ExecuteReader</code>, <code>ExecuteScalar</code> or <code>ExecuteNonQuery</code> that I can get the affected rows for select queries?</p>
  
  <p><strong>I CAN'T CHANGE THE SCRIPTS</strong></p>
  
  <p>Edit: As pointed out by <a href="https://stackoverflow.com/users/11683/gserg">GSerg</a> this could be a duplicate, but I'm already using a Handler and the string is empty</p>
  
  <p>Here is the MessageHandler Sub</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub InfoMessageHandler(sender As Object, e As SqlClient.SqlInfoMessageEventArgs)
      stringBuilder.Append(e.Message).AppendLine()
  End Sub
  </code></pre>
  
  <p>And I'm declaring the stringBuilder as a global variable like this</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim stringBuilder As New StringBuilder
  </code></pre>
  
  <p>The result is an empty string when running this</p>
  
  <pre class="lang-vb prettyprint-override"><code>MessageBox.Show("String Builder: " &amp; stringBuilder.ToString)
  </code></pre>
  
  <p>So I don't have any way to just get the "Messages" text?</p>
  
  <p>Edit 2:
  As a quick fix I'm using the following code</p>
  
  <pre><code>While reader.Read()
     rowCount = rowCount + 1
  End While
  </code></pre>
  
  <p>But I would still like to know if it is possible to get the actual "Messages" text</p>