how to get the results of sp_stored_procedures in C# app?

The result of sp_stored_procedures and many others is a result set, a table, but this procedure and others return only an integer. How do I get the result set in C# code I need a general idea how it is done.

Thanks.




Answer this question

how to get the results of sp_stored_procedures in C# app?

  • thegreat1

    If the procedure provides more than one resultsset, you will have to switch between the resultsets to retrieve the resultset you want to get. ( As a procedure can have more than one returned table ) E.g. If you use a datareader you can switch to the next next result.

    HTH, Jens K. Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---


  • UtterMan

    Are you looking for something like this:

    using (SqlConnection cxn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Master;Integrated Security=True"))
    {
    cxn.Open();
    SqlCommand cmd = new SqlCommand("sp_stored_procedures", cxn);
    SqlDataReader rdr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

    while (rdr.Read())
    {
    for (int i = 0; i < rdr.FieldCount; i++)
    {
    Console.Write(rdrIdea.ToString() + "\t");
    }
    Console.WriteLine();
    }

    cmd.Dispose();
    }



  • Thorri

    Jens K. Suessmeyer wrote:

    If the procedure provides more than one resultsset, you will have to switch between the resultsets to retrieve the resultset you want to get. ( As a procedure can have more than one returned table ) E.g. If you use a datareader you can switch to the next next result.

    HTH, Jens K. Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---

    Jens, thanks a lot.



  • Bev Kaufman

    Jeff Papiez - MSFT wrote:

    Are you looking for something like this:

    using (SqlConnection cxn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial ();
    }

    Thank you very much, Jeff.



  • how to get the results of sp_stored_procedures in C# app?