Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ____________________________________________________APP Config________________________________________________________________________
- <connectionStrings>
- <add name="YourDB" connectionString="Data Source=LocalHost;Initial Catalog='NAME OF THE DATABASE';Integrated Security=True" providerName="System.Data.SqlClient"></add>
- </connectionStrings>
- ____________________________________________________REPOSITORY__________________________________________________________________________
- public CurrencyModel GetCurrencyRate(string curCode)
- {
- CurrencyModel currency = new CurrencyModel();
- using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["YourDB"].ConnectionString)) // Create connection
- using (var cmd = conn.CreateCommand()) // Open up for Query
- {
- try
- {
- conn.Open(); // Open connection
- cmd.CommandText = "SELECT id, CurrencyCode, ExchangeRateToUSD, ExchangeRateToEUR FROM dbo.CurrencyRates WHERE CurrencyCode= @code"; // Execute Query
- cmd.Parameters.AddWithValue("@code", curCode);
- using (var rdr = cmd.ExecuteReader()) // Prep reader
- {
- while (rdr.Read()) // Read
- {
- currency.Id = Convert.ToInt32(rdr["ID"]);
- currency.CurrencyCode = Convert.ToString(rdr["CurrencyCode"]);
- currency.ExchangeRateToDollar = Convert.ToDouble(rdr["ExchangeRateToUSD"]);
- currency.ExchangeRateToEur = Convert.ToDouble(rdr["ExchangeRateToEUR"]);
- }
- }
- }
- catch(Exception ex)
- {
- log.LogIt(LogErrorCode.Error, "Exception when trying to get Currency Rate with curCode:" + curCode, ex);
- }
- return currency;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement