Question

I have a stored procedure that contains multiple selects a bit like this:

select 'Connected'
exec DoWork
  @var1 = 23,
  @var2 = 400
select 'Done'
select 'Bye'

When I call the stored procedure from my C# code I only get a single result in my SqlDataReader and it is the 'Connected' select.

I call it like this

SqlCommand command = connection.CreateCommand();
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = "SP_MyProc";
command.Parameters.Add("@val", "TEST");
SqlDataReader reader = command.ExecuteReader();

while (reader.Read())
{
    string temp = "";

    for (int i = 0; i < reader.FieldCount; i++)
    {
       temp += reader.GetString(i) + " ";
    }

    worker.ReportProgress(0, temp);
}

connection.Close();

It makes sense that normally a stored procedure only returns a single result set, however I need this for debugging purposes. Is it possible to do?

Was it helpful?

Solution

use the SqlDataReader NextResult

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top