DataSet的保存XML

wangchangk 2009-07-08 08:29:09
我现在从数据库取出几张表到DataSet,然后通过方法
XmlDocument doc = new XmlDocument();
doc.LoadXml(DataSet.GetXml());
doc.Save(@"C:\xxx.xml");
但是如果在数据库中有个字段值为null或者为空则该字段不会保存到XML文件,我想要的结果是无论有没有值都需要改字段,请问我这种方法不行吗?用什么方法
...全文
33 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
binhu12332100 2009-07-09
  • 打赏
  • 举报
回复
来学习的&
jdhlowforever 2009-07-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 itliyi 的回复:]
//实例化文档对象 版本信息 根元素
XmlDocument xml = new XmlDocument();
XmlDeclaration xel = xml.CreateXmlDeclaration("1.0", "utf-8", null);
xml.InsertBefore(xel, xml.DocumentElement);//版本信息放入跟元素前面
XmlElement root = xml.CreateElement("T"); //实例化一级子节点
for (int i = 0; i < DataSet.Tables[0].Rows.Count; i++)
{
  XmlElement t =xml.CreateElement("TT");
    for (int j = 0; j < DataSet.Tables[0].Columns.Count; j++)
    {
      XmlElement tt =xml.CreateElement(DataSet.Tables[0].Columns[j].ToString());
      tt.InnerText = DataSet.Tables[0].Rows[i][j].ToString();
      t.AppendChild(tt);
    }
      root.AppendChild(t);
}
    xml.AppendChild(root);
    xml.Save(Path.Combine(Application.StartupPath, "xxxx.xml"));
    MessageBox.Show("OK"); tt.InnerText = ds.Tables[0].Rows[i][j].ToString();
[/Quote]

不错,看起来是好东西!
fanglong168 2009-07-09
  • 打赏
  • 举报
回复
学习
IHandler 2009-07-09
  • 打赏
  • 举报
回复
SELECT列的列表中对有NULL或空值的列用ISNULL处理一下,赋个默认值
wuyq11 2009-07-08
  • 打赏
  • 举报
回复
遍历dataset数据集
操作XML添加节点
参考
itliyi 2009-07-08
  • 打赏
  • 举报
回复
//实例化文档对象 版本信息 根元素
XmlDocument xml = new XmlDocument();
XmlDeclaration xel = xml.CreateXmlDeclaration("1.0", "utf-8", null);
xml.InsertBefore(xel, xml.DocumentElement);//版本信息放入跟元素前面
XmlElement root = xml.CreateElement("T"); //实例化一级子节点
for (int i = 0; i < DataSet.Tables[0].Rows.Count; i++)
{
XmlElement t =xml.CreateElement("TT");
for (int j = 0; j < DataSet.Tables[0].Columns.Count; j++)
{
XmlElement tt =xml.CreateElement(DataSet.Tables[0].Columns[j].ToString());
tt.InnerText = DataSet.Tables[0].Rows[i][j].ToString();
t.AppendChild(tt);
}
root.AppendChild(t);
}
xml.AppendChild(root);
xml.Save(Path.Combine(Application.StartupPath, "xxxx.xml"));
MessageBox.Show("OK"); tt.InnerText = ds.Tables[0].Rows[i][j].ToString();

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧