Click here to Skip to main content
15,915,065 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
i have a currency table,that contain 4 Currency SGD,INR,USD AUD,I need to convert the total 12 conversion Using this api

C#
public static string CurrencyConvert(decimal amount, string fromCurrency, string toCurrency)
   {

       //Grab your values and build your Web Request to the API
       string apiURL = String.Format("https://www.google.com/finance/converter?a={0}&from={1}&to={2}&meta={3}", amount, fromCurrency, toCurrency, Guid.NewGuid().ToString());

       //Make your Web Request and grab the results
       var request = WebRequest.Create(apiURL);

       //Get the Response
       var streamReader = new StreamReader(request.GetResponse().GetResponseStream(), System.Text.Encoding.ASCII);

       //Grab your converted value (ie 2.45 USD)
       var result = Regex.Matches(streamReader.ReadToEnd(), "<span class=\"?bld\"?>([^<]+)</span>")[0].Groups[1].Value;

       //Get the Result
       return result;
   }

SGD to INR;
SGD to USD;
SGD to AUD,

INR to SGD,
INR to USD,
INR to AUD,

AUD to SGD,
AUD to INR,
AUD to USD,

USD to SGD
USD to AUD,
USD to INR,
Posted
Updated 21-Dec-15 2:47am
v4
Comments
Kornfeld Eliyahu Peter 20-Dec-15 12:23pm    
And how you intend to do that? Using your own table for rates or use some online service for that?
Any starting?
Member 12072368 21-Dec-15 7:52am    
I nintegrate google api ("https://www.google.com/finance/converter?a={0}&from={1}&to={2}&meta={3}")
using this link i need to cunvert 4 curruncy each other

Kornfeld Eliyahu Peter 21-Dec-15 8:05am    
So? And where is the problem? Call the link with all the combinations and you will have to rate for the moment for each and every one...
Member 12072368 21-Dec-15 13:21pm    
public static string CurrencyConvert1()
{

decimal amount = 1;
string fromCurrency = "SGD";
string toCurrency = "INR";
//Grab your values and build your Web Request to the API
string apiURL = String.Format("https://www.google.com/finance/converter?a={0}&from={1}&to={2}&meta={3}", amount, fromCurrency, toCurrency, Guid.NewGuid().ToString());

//Make your Web Request and grab the results
var request = WebRequest.Create(apiURL);

//Get the Response
var streamReader = new StreamReader(request.GetResponse().GetResponseStream(), System.Text.Encoding.ASCII);

//Grab your converted value (ie 2.45 USD)
var result = Regex.Matches(streamReader.ReadToEnd(), "<span class=\"?bld\"?>([^<]+)</span>")[0].Groups[1].Value;
result = result.Replace(toCurrency, "").Trim();
List<tools.sqlcontainer> SQLCommands = new List<tools.sqlcontainer>();
Tools.SqlContainer SQLContainer = new Tools.SqlContainer();
List<sqlparameter> SqlParameters = new List<sqlparameter>();
string ErrorIfAny = string.Empty;
DataSet ds = new DataSet();

SQLContainer.Query = "[Create_Convertion] @fromCurrency,@toCurrency,@conversionrate";

SqlParameters.Add(new SqlParameter("@fromCurrency", fromCurrency));
SqlParameters.Add(new SqlParameter("@toCurrency", toCurrency));
SqlParameters.Add(new SqlParameter("@conversionrate", result));
SQLContainer.SqlParameters = SqlParameters;
SQLCommands.Add(SQLContainer);
bool stat = Tools.GetData(SQLCommands, out ds, out ErrorIfAny);
this is for Single Combination to get the Current conversionrate and insert my datatable
Patrice T 20-Dec-15 12:52pm    
Start to work, unless you have a question.

1 solution

 
Share this answer
 
Comments
Member 12072368 22-Dec-15 3:48am    
how to insert the conversion rate to database

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900