XmlDataDocument与DataSet相互转化
时间:2011-05-27 来源:笨笨的菜鸟
1.
View Code1 using System.Text;
2 using System.IO;
3
4 XmlNode xmlNode1;
5 XmlDataDocument xd=new XmlDataDocument();
6 StringBuilder xmlString1;
7
8 xmlNode1=DataSet1;//DataSet1为返回的数据集
9 if(xmlNode1==null) //--存储过程执行失败
10 return;
11 xmlString1=new StringBuilder(xmlNode1.OuterXml);
12 if(xmlString1.ToString().Equals("<NewDataSet xmlns=\"\"></NewDataSet>")) return ;
13 xd.LoadXml(xmlString1.ToString());
14 DataSet ds=new DataSet();
15 ds.ReadXml(new XmlNodeReader(xd));
16 DataGrid1.DataSource=ds.Tables[0].DefaultView;
17 DataGrid1.DataBind();
18
2
View Code1 XmlDataDocument xd=new XmlDataDocument();
2
3 if((int)ds.Tables[0].DefaultView.Count<1)
4 {
5 string xml="<NewDataSet></NewDataSet>";
6 xd.LoadXml(xml);
7 return xd;
8 }
9 xd=new XmlDataDocument(ds);
10 XmlNode root1=xd.DocumentElement;
11 XmlNodeList roots=root1.SelectNodes("list");
12 foreach(XmlNode roota in roots) //为所有元素加上站点名称标记
13 {
14 XmlElement Link=xd.CreateElement("SiteName");
15 Link.InnerText=ConfigurationSettings.AppSettings["SiteName"].ToString();
16 roota.AppendChild(Link);
17 }
18 return xd;
相关阅读 更多 +