step 1
using System.Configuration;
step 2
add string connection string in file webconfig
<add name="default" connectionString="Driver={Microsoft Access Driver (*.mdb)}; DBQ=part-file database;"/>
step 3
create string connection on file cs
public String strcon = ConfigurationManager.ConnectionStrings["default"].ConnectionString;
วันพฤหัสบดีที่ 17 เมษายน พ.ศ. 2557
Exchange-rate by yahoo
step 1
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
step2
create class ConvertCurrency
public static decimal ConvertCurrency(decimal amount, string from, string to)
{
try
{
WebClient web = new WebClient();
const string urlPattern = "http://finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=l1";
string url = String.Format(urlPattern, from, to);
string response = new WebClient().DownloadString(url);
decimal exchangeRate = decimal.Parse(response, System.Globalization.CultureInfo.InvariantCulture);
return exchangeRate;
}
catch (Exception ex)
{
return 0;
}
}
step 3
core function
decimal apiRate = 0;
apiRate =Class1.ConvertCurrency(1, "USD", "THB");
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
step2
create class ConvertCurrency
public static decimal ConvertCurrency(decimal amount, string from, string to)
{
try
{
WebClient web = new WebClient();
const string urlPattern = "http://finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=l1";
string url = String.Format(urlPattern, from, to);
string response = new WebClient().DownloadString(url);
decimal exchangeRate = decimal.Parse(response, System.Globalization.CultureInfo.InvariantCulture);
return exchangeRate;
}
catch (Exception ex)
{
return 0;
}
}
step 3
core function
decimal apiRate = 0;
apiRate =Class1.ConvertCurrency(1, "USD", "THB");
สมัครสมาชิก:
บทความ (Atom)