Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. ____________________________________________________APP Config________________________________________________________________________
  2. <connectionStrings>
  3. <add name="YourDB" connectionString="Data Source=LocalHost;Initial Catalog='NAME OF THE DATABASE';Integrated Security=True" providerName="System.Data.SqlClient"></add>
  4. </connectionStrings>
  5.  
  6. ____________________________________________________REPOSITORY__________________________________________________________________________
  7. public CurrencyModel GetCurrencyRate(string curCode)
  8. {
  9. CurrencyModel currency = new CurrencyModel();
  10. using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["YourDB"].ConnectionString)) // Create connection
  11. using (var cmd = conn.CreateCommand()) // Open up for Query
  12. {
  13. try
  14. {
  15.  
  16.  
  17. conn.Open(); // Open connection
  18. cmd.CommandText = "SELECT id, CurrencyCode, ExchangeRateToUSD, ExchangeRateToEUR FROM dbo.CurrencyRates WHERE CurrencyCode= @code"; // Execute Query
  19. cmd.Parameters.AddWithValue("@code", curCode);
  20. using (var rdr = cmd.ExecuteReader()) // Prep reader
  21. {
  22. while (rdr.Read()) // Read
  23. {
  24. currency.Id = Convert.ToInt32(rdr["ID"]);
  25. currency.CurrencyCode = Convert.ToString(rdr["CurrencyCode"]);
  26. currency.ExchangeRateToDollar = Convert.ToDouble(rdr["ExchangeRateToUSD"]);
  27. currency.ExchangeRateToEur = Convert.ToDouble(rdr["ExchangeRateToEUR"]);
  28. }
  29. }
  30.  
  31.  
  32. }
  33. catch(Exception ex)
  34. {
  35. log.LogIt(LogErrorCode.Error, "Exception when trying to get Currency Rate with curCode:" + curCode, ex);
  36. }
  37. return currency;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement