public DataSet GetData(string httpUrl)
{
string XMLPath = @"http地址"; // 該地址不能包含中文
DataSet ds = new DataSet();
WebClient wc = new WebClIEnt();
byte[] bt = wc.DownloadData(XMLPath);
XmlDocument xd = new XMLDocument();
string source = Byte2String(bt);
xd.LoadXML(source);
XmlNodeReader xnr = new XMLNodeReader(xd);
ds.ReadXML(xnr);
DataTable dt = ds.Tables[0];
this.DataGrid1.DataSource = ds;
this.DataGrid1.DataBind();
return ds;
}
public static string Byte2String(byte[] bt)
{
System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("gb2312");
string str = encoding.GetString(bt);
return str;
}
出處:http://www.brtech.com.cn