Posted By

lfbarbieri on 05/09/07


Tagged

database sql stored procedure reader ExecuteReader


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


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.