Stored Procedure to provide results gives exception in c# code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dbrewerton
    New Member
    • Nov 2009
    • 115

    Stored Procedure to provide results gives exception in c# code

    Ok, I'm not exactly certain what the problem is here but I will say I'm frustrated. The Stored Proc if directly executed works fine. When I try using it as part of loading a data table, it give an exception. However, the exception isn't really giving me any specific conditions, it says there's a problem but no details. My code:

    Code:
                    try
                    {
                        using (SqlCommand command = new SqlCommand("sp_TestProc", sqlconn))
                        {
                            command.CommandType = CommandType.StoredProcedure;
                            sqlconn.Open(); // opening the connection
    
                            SqlDataReader dr = command.ExecuteReader(); // this is where it goes south
    
    
                            DataTable dtt = new DataTable();
                            dtt.Load(dr);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error: " + ex.ToString());
                    }
                    finally
                    {
                        sqlconn.Close();
                    }
Working...