private string ConvertDataTableToXML(DataTable xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
{
stream = new MemoryStream();
writer = new XmlTextWriter(stream, Encoding.Default);
xmlDS.WriteXml(writer);
int count = (int)stream.Length;
byte[] arr = new byte[count];
stream.Seek(, SeekOrigin.Begin);
stream.Read(arr, , count);
UTF8Encoding utf = new UTF8Encoding();
return utf.GetString(arr).Trim();
}
catch
{
return String.Empty;
}
finally
{
if (writer != null) writer.Close();
}
}
private DataSet ConvertXMLToDataSet(string xmlData)
{
StringReader stream = null;
XmlTextReader reader = null;
try
{
DataSet xmlDS = new DataSet();
stream = new StringReader(xmlData);
reader = new XmlTextReader(stream);
xmlDS.ReadXml(reader);
return xmlDS;
}
catch (Exception ex)
{
string strTest = ex.Message;
return null;
}
finally
{
if (reader != null)
reader.Close();
}
}

C#实现XML与DataTable互转的更多相关文章

  1. Xml与DataTable相互转换方法

    1.Xml与DataTable相互转换方法:http://www.cnblogs.com/lilin/archive/2010/04/18/1714927.html

  2. XML 和 List 互转类

    XML 和 List 互转类 using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

  3. JavaScript实现XML与JSON互转代码(转载)

    下面来分享一个关于JavaScript实现XML与JSON互转例子,这里面介绍了国外的三款xml转json的例子,希望这些例子能给你带来帮助. 最近在开发在线XML编辑器,打算使用JSON做为中间格式 ...

  4. Json、JavaBean、Map、XML之间的互转

    思路是JavaBean.Map.XML都可以用工具类很简单的转换为Json,进而实现互相转换 1.Map.XML与Json互转 mvn依赖 <dependency> <groupId ...

  5. JAVA中 XML与数据库互转 学习笔记三

    要求 必备知识 JAVA基础知识,XML基础知识,数据库的基本操作. 开发环境 MyEclipse10/MySql5.5 资料下载 源码下载   数据库在数据查询,修改,保存,安全等方面与其他数据处理 ...

  6. c++实现Xml和json互转【转】

    https://blog.csdn.net/kfy2011/article/details/51774242 1.下载c语言的cJson库源码,库很小,只有两个文件cJSON.c和cJSON.h.下载 ...

  7. java中XML操作:xml与string互转、读取XML文档节点及对XML节点增删改查

    一.XML和String互转: 使用dom4j程式变得很简单 //字符串转XML String xmlStr = \"......\"; Document document = D ...

  8. List和DataTable互转

    /// <summary> /// List和DataTable互转 /// </summary> static class ListUtility { /// <sum ...

  9. SQL2008使用json.net实现XML与JSON互转

    借助CLR,首先实现字符串的互转,然后使用存储过程实现JSON2table     public class JsonFunction    {        /// <summary> ...

随机推荐

  1. Jquery Mobile开发以及Js对象动态绑定

    动态创建对象并绑定属性: var instantiate = function (Type, args) { var Constructor = function () { }; Constructo ...

  2. Knockout.js随手记(1)

    新的开始,knockout.js 1.首先去http://knockoutjs.com/index.html下载knockout.js,最新的版本是2.3 2.知道什么是Knockout?它是个Jav ...

  3. cmd中编译java

    cmd定位到.java文件所在位置: 注意.java文件名应与类名相同. javac xxx.java:编译(生成.class文件): java xxx:运行(执行.class文件): 若类间相互调用 ...

  4. JavaScript 富文本编辑器

    WEB项目中使用UEditor(富文本编辑器) UEditor - 完整示例 http://ueditor.baidu.com/website/onlinedemo.html UEditor注意事项: ...

  5. 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS

    [Usaco2005 Dec]Knights of Ni 骑士 Description  贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...

  6. CentOS系统配置记录

    1. 挂載 ntfs: 确定已经安装了rpmforge软件库的源.在线安装使用 yum install 命令 含有 rpmforge源. yum install fuse ntfs-3g -y 安装后 ...

  7. 谓词 (NSPredicate)使用详情

    谓词 更加详细:http://blog.csdn.net/ztp800201/article/details/8116081 //判断是否满足条件 第一种 判断一个数组(array)中满足条件的 NS ...

  8. ACM: FZU 2112 Tickets - 欧拉回路 - 并查集

     FZU 2112 Tickets Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u P ...

  9. c#操作mysql积累

    1,连接字符串 Server=localhost;port=;User ID=root;password=admin;database=;charset=utf8;Allow User Variabl ...

  10. 访问本地json文件因跨域导致的问题

    我使用jquery的getJSON的方法获取本地的json文件,并进行操作,获取json 数据代码如下: $.getJSON("invite_panel.json",functio ...