DataSet数据插入到XML中
来源:互联网 发布:网络管理维护 编辑:程序博客网 时间:2024/05/16 15:44
/// <summary>
/// 把dataset数据存到xml文件中
/// </summary>
/// <param name="set">dataset数据表</param>
/// <param name="path">文件要保存到那(虚拟路径)</param>
/// <param name="sqlziduan">数据库中取出的表中的字段</param>
/// <param name="sqlziduan1">数据库中取出的表中的字段</param>
/// <param name="FileName">数据保存成功后,需要保存的路径(物理路径或者根路径)</param>
/// <returns>文件虚拟路径</returns>
public string XmlFile(DataSet set,string path,string sqlziduan,string sqlziduan1,string FileName,string caption,string xName,string yName)
{
XmlClass_zhao xmlclass = new XmlClass_zhao();
//string path = "temp/a.xml";
if (这里面是把dataset数据转换成xml文件)
{
string xmlstring = "<?xml version='1.0' encoding='utf-8' ?><graphcaption='"+caption.ToString()+"' xAxisName='"+xName.ToString()+"'yAxisName='"+yName.ToString()+"' showNames='1' decimalPrecision='0'formatNumberScale='0' ></graph>";
XmlDocument xml = new XmlDocument();
xml.LoadXml(xmlstring);
XmlDocumentFragment fra = xml.CreateDocumentFragment();
//DataView da = set.Tables[0].DefaultView;
for (int i = 0; i < 8; i++)
{
//string stm = set.Tables[0].Rows[i][sqlziduan].ToString();
string xmlst = "<set name='" + set.Tables[0].Rows[i][sqlziduan].ToString() + "' value='" + set.Tables[0].Rows[i][sqlziduan1].ToString() + "' color='AFD8F8'/>";
fra.InnerXml = xmlst;
xml.DocumentElement.AppendChild(fra);
}
xml.Save(FileName);
#region 另一种方法
//try
//{
// string xmlstring = "<graph caption='每月销售额柱形图' xAxisName='月份' yAxisName='Units' showNames='1' decimalPrecision='0' formatNumberScale='0' ></graph>";
// XmlNode currNode;
// XmlDocument doc = new XmlDocument();
// doc.LoadXml(xmlstring);
// XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
// for (int i = 0; i <da.Count; i++)
// {
// string xmlst = "<set name='" + set1.Tables[0].Rows[0][i].ToString() + "' value='"+set1.Tables[0].Rows[1][i].ToString()+"' color='AFD8F8'/>";
// docFrag.InnerXml = st;
// currNode = doc.DocumentElement.FirstChild;
// currNode.InsertAfter(docFrag, currNode.LastChild);
// }
// doc.Save("a.xml");
//}
//catch (Exception e)
//{
// Console.WriteLine("Exception: {0}", e.ToString());
//}
#endregion
}
return path;
}
/// 把dataset数据存到xml文件中
/// </summary>
/// <param name="set">dataset数据表</param>
/// <param name="path">文件要保存到那(虚拟路径)</param>
/// <param name="sqlziduan">数据库中取出的表中的字段</param>
/// <param name="sqlziduan1">数据库中取出的表中的字段</param>
/// <param name="FileName">数据保存成功后,需要保存的路径(物理路径或者根路径)</param>
/// <returns>文件虚拟路径</returns>
public string XmlFile(DataSet set,string path,string sqlziduan,string sqlziduan1,string FileName,string caption,string xName,string yName)
{
XmlClass_zhao xmlclass = new XmlClass_zhao();
//string path = "temp/a.xml";
if (这里面是把dataset数据转换成xml文件)
{
string xmlstring = "<?xml version='1.0' encoding='utf-8' ?><graphcaption='"+caption.ToString()+"' xAxisName='"+xName.ToString()+"'yAxisName='"+yName.ToString()+"' showNames='1' decimalPrecision='0'formatNumberScale='0' ></graph>";
XmlDocument xml = new XmlDocument();
xml.LoadXml(xmlstring);
XmlDocumentFragment fra = xml.CreateDocumentFragment();
//DataView da = set.Tables[0].DefaultView;
for (int i = 0; i < 8; i++)
{
//string stm = set.Tables[0].Rows[i][sqlziduan].ToString();
string xmlst = "<set name='" + set.Tables[0].Rows[i][sqlziduan].ToString() + "' value='" + set.Tables[0].Rows[i][sqlziduan1].ToString() + "' color='AFD8F8'/>";
fra.InnerXml = xmlst;
xml.DocumentElement.AppendChild(fra);
}
xml.Save(FileName);
#region 另一种方法
//try
//{
// string xmlstring = "<graph caption='每月销售额柱形图' xAxisName='月份' yAxisName='Units' showNames='1' decimalPrecision='0' formatNumberScale='0' ></graph>";
// XmlNode currNode;
// XmlDocument doc = new XmlDocument();
// doc.LoadXml(xmlstring);
// XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
// for (int i = 0; i <da.Count; i++)
// {
// string xmlst = "<set name='" + set1.Tables[0].Rows[0][i].ToString() + "' value='"+set1.Tables[0].Rows[1][i].ToString()+"' color='AFD8F8'/>";
// docFrag.InnerXml = st;
// currNode = doc.DocumentElement.FirstChild;
// currNode.InsertAfter(docFrag, currNode.LastChild);
// }
// doc.Save("a.xml");
//}
//catch (Exception e)
//{
// Console.WriteLine("Exception: {0}", e.ToString());
//}
#endregion
}
return path;
}
- DataSet数据插入到XML中
- 读取xml数据到DataSet
- 读取XML数据到DataSet
- C#读取xml文档数据到DataSet
- DataSet数据集导出到Xml文件
- 读XML资源到DataSet中
- DataSet中直接导出XML数据并且写到HTTP输出流中
- java实现读取XML文件数据插入到数据库中
- 将dataset中的数据写入xml中
- 将xml文件的数据载入到DataSet中,在读取出来
- asp.net中使用Dataset导出数据到xml或者xls
- 在.NET中使用XML、读取XML文件,插入数据到XML文档中。
- dataset读取excel中的数据到打dataset中
- DataSet插入数据
- 将DataSet数据写入到listview中
- 导出DataSet的数据到Excel中
- 将多个DataTable添加到指定的DataSet中,转换DataSet为XML,将DataTable转换XML
- 实现DataSet插入到数据库
- 产品打磨日记-给SA交待的任务
- Python如何创建一个模块?以及模块导入
- 微观架构及宏观架构
- linux下usb gadget 模拟键盘
- 各种类型转换
- DataSet数据插入到XML中
- 获取手机刚拍照的图片和获取手机内所有图片
- 学习vc的心得
- eclipse中的maven管理之配置与依赖的查找和替换(二)
- 斯坦福大学公开课:iPhone开发教程2010年冬> 创建应用程序
- Ubuntu12.04无法使用vim系统剪贴板解决方法
- snmp VC6.0 编译error LNK2001: unresolved external symbol出错解决办法
- IOCP 模型
- 网卡驱动:传输超时watchdog_timeo/ndo_tx_timeout