基本信息
源码名称:c# 读取xml数据到datagrid中实例 附完整源码
源码大小:0.02M
文件格式:.zip
开发语言:C#
更新时间:2013-04-23
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
读取address.xml中的数据,并显示到datagrid中
address.xml:
<Address_Table> <address> <name>dongdong</name> <Email>dongdong@163.com</Email> <mobile>13912345678</mobile> <phone>67681234</phone> <home>XiTu City Road No.23</home> </address> <address> <name>xixi</name> <Email>xixi@21.cn</Email> <mobile>13812345678</mobile> <phone>81234567</phone> <home>TaiLan Mansion No.1008 Room</home> </address> <address> <name>chai</name> <Email>cf@263.net</Email> <mobile>13109876543</mobile> <phone>98768765</phone> <home>MaiLei Road No.8</home> </address> </Address_Table>
读取代码:
// 申明一个数据集 DataSet dsAddress = new DataSet("address"); // 读取XML文件,并将读到的数据内容显示在DataGrid组件中。 private void btnReadXML_Click(object sender, System.EventArgs e) { string filePath = "address.xml"; dsAddress.ReadXml(filePath); dataGrid1.DataSource = dsAddress; dataGrid1.DataMember = "address"; dataGrid1.CaptionText = dataGrid1.DataMember; } // 显示XML文件的框件结构 private void btnShowSchema_Click(object sender, System.EventArgs e) { System.IO.StringWriter swXML = new System.IO.StringWriter(); dsAddress.WriteXmlSchema(swXML); textBox1.Text = swXML.ToString(); }