NEWS

Lấy tỷ giá ngoại tệ trực tuyến Vietcombak

Lấy tỷ giá ngoại tệ trực tuyến Vietcombak
Đăng bởi: Hoàng Tử Nhỏ - Lượt xem: 22877 18:22:59, 15/10/2015C#   In bài viết

Bài viết này mình sẽ hướng dẫn các bạn cách lấy tỷ giá ngoại tệ của Ngân hàng Vietcombank trực tuyến. Trước tiên bạn truy cập vào trang web của Ngân hàng Vietcombank https://www.vietcombank.com.vn/exchangerates/.

Lấy tỷ giá ngoại tệ trực tuyến Vietcombank vs C#

Tại đây chú ý đến nút "XML" đây chính là dữ liệu mình cần xử lý. Bạn thiết kế form cơ bản như sau, bài viết này mình sử dụng listview để load dữ liệu. Listview bạn thêm 5 cột gồm, CurrencyCode, CurrencyName, Buy, Transfer, Sell.

Trước tiên bạn import thư viện xml vào.

using System.Xml;

Tại sự kiện form load bạn viết code như sau:

private void Form1_Load(object sender, EventArgs e)
{
            XmlDocument xml = new XmlDocument();
            xml.Load("http://www.vietcombank.com.vn/exchangerates/ExrateXML.aspx");

            XmlNodeList noXml;
            noXml = xml.SelectNodes("/ExrateList/Exrate");
            int i=0;
            for (i = 0;i<= noXml.Count -1;i++)
            {
                ListViewItem item = new       ListViewItem(noXml.Item(i).Attributes["CurrencyCode"].InnerText);
                item.SubItems.Add(noXml.Item(i).Attributes["CurrencyName"].InnerText);
                item.SubItems.Add(noXml.Item(i).Attributes["Buy"].InnerText);
                item.SubItems.Add(noXml.Item(i).Attributes["Transfer"].InnerText);
                item.SubItems.Add(noXml.Item(i).Attributes["Sell"].InnerText);
                liv_DanhSach.Items.Add(item);


            }

}

Nhấn F5 và thưởng thức thành quả. Lưu ý máy phải kết nối internet mới sử dụng được nha.

Chúc các bạn thành công.

 

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

Lấy tỷ giá ngoại tệ trực tuyến Vietcombak
Đăng bởi: Hoàng Tử Nhỏ - Lượt xem: 22877 18:22:59, 15/10/2015C#   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.