By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,466 Members | 1,032 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,466 IT Pros & Developers. It's quick & easy.

Stored Procedure to provide results gives exception in c# code

dbrewerton
100+
P: 115
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:

Expand|Select|Wrap|Line Numbers
  1.                 try
  2.                 {
  3.                     using (SqlCommand command = new SqlCommand("sp_TestProc", sqlconn))
  4.                     {
  5.                         command.CommandType = CommandType.StoredProcedure;
  6.                         sqlconn.Open(); // opening the connection
  7.  
  8.                         SqlDataReader dr = command.ExecuteReader(); // this is where it goes south
  9.  
  10.  
  11.                         DataTable dtt = new DataTable();
  12.                         dtt.Load(dr);
  13.                     }
  14.                 }
  15.                 catch (Exception ex)
  16.                 {
  17.                     Console.WriteLine("Error: " + ex.ToString());
  18.                 }
  19.                 finally
  20.                 {
  21.                     sqlconn.Close();
  22.                 }
  23.  
3 Weeks Ago #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.