We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

lfbarbieri on 05/09/07


Tagged

database sql stored procedure reader ExecuteReader


Versions (?)


Database Retrieve


Published in: C# 


  1. try
  2. {
  3. // Create and open a connection object
  4. conn = new SqlConnection(configurationConnString);
  5. conn.Open();
  6.  
  7. // Set Stored Proc
  8. SqlCommand cmd = new SqlCommand("spGetConfigSettingsByApplication", conn);
  9. cmd.CommandType = CommandType.StoredProcedure;
  10.  
  11. // Set Parameters
  12. cmd.Parameters.Add(new SqlParameter("@applicationName", SqlDbType.NVarChar, 50));
  13. cmd.Parameters["@applicationName"].Value = "FTU";
  14.  
  15. // execute the command
  16. rdr = cmd.ExecuteReader();
  17.  
  18. // iterate through results, printing each to console
  19. while (rdr.Read())
  20. {
  21. configSettings.Add(rdr["AppKey"], rdr["AppValue"]);
  22. }
  23. }
  24. finally
  25. {
  26. if (conn != null) conn.Close();
  27. if (rdr != null) rdr.Close();
  28. }

Report this snippet 

You need to login to post a comment.