设为首页 加入收藏 网站搜索 繁體中文 中国建站网 — 站长资源分享平台

利用WebClient获取远程数据(仅做备份)

来源:网络收集 作者:佚名 时间:2007-04-25 23:08:49

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

Tags:

  • 好的评价 如果您觉得好,就请您
      0%(0)
  • 差的评价 如果您觉得差,就请您
      0%(0)
  • 相关文章
    广告赞助

    文章随便看看 设计素材 建站学院 网页模板 视频教程

    网友评论

    共有 0 位网友发表了评论,得分 0 分,平均 0 分    查看完整评论

    用户名: 查看更多评论

    分 值:100分 85分 70分 55分 40分 25分 10分 1分

    内 容:

             通知管理员 验证码: