Note that there are some explanatory texts on larger screens.

plurals
  1. POSqlDataReader only returns first select in SqlCommand
    primarykey
    data
    text
    <p>I'm using a <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.aspx" rel="nofollow noreferrer">SqlCommand</a> to execute a sql statement on a SqlServer2005 db. ( I also tried <a href="http://msdn.microsoft.com/en-us/library/system.data.common.dbcommand.aspx" rel="nofollow noreferrer">DbCommand</a>.)</p> <p>If I execute this sql in SQL Server Management Studio, I can send the "Results to Text". I would like to capture this text in my C# code.</p> <p><a href="https://stackoverflow.com/questions/663716/using-sqlcommand-to-execute-a-non-query-can-you-get-to-text-normally-posted-to">This</a> and <a href="https://stackoverflow.com/questions/547040/ms-sql2005-query-stored-proc-results-to-text-using-sqlcommand-or-such">this</a> are related questions, but not the same:</p> <p>My sql contains, next to print statements, also different select statements:</p> <pre><code>PRINT 'We are here' SELECT Name FROM Table1 -- do some logic SELECT Name, Country FROM Table1 PRINT 'We are done' </code></pre> <p>( "<em>Strange sql</em>" I hear you say. I know, but this is what our long-living maintenance scripts look like.)</p> <p>I can use the SqlConnection.InfoMessage to catch the PRINT statements separately.</p> <p>But SqlDataReader doesn't seem to support the 2 select statements, both with a different FieldCount.</p> <p>I'm afraid I'm stuck with Process.Start and the sql server command line sqlcmd and reading the output, but I was looking for something more <em>API'ish</em>.</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload