易截截图软件、单文件、免安装、纯绿色、仅160KB

DataSet(DataTable)与XML互转

using System;
using System.Data;
using System.IO;
using System.Xml;
using System.Text;
// 相应C#代码:
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(0, SeekOrigin.Begin);
stream.Read(arr, 0, 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();
}
}


相关文档:

xml与DataSet的互转换类

以前在博客上发过,经人提醒DataSet已自带读写XML的功能,于是便删了,
不过在实践中感觉封装一层后,使用起来还是蛮方便的。故再次重发。
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Xml;
namespace XmlDesign
{
class XmlDatasetC ......

把xml 转dataset

///通过传入的特定XML字符串,通过 ReadXml函数读取到DataSet中。
protected static DataSet GetDataSetByXml(string xmlData)
{
           try
           {
       &nbs ......

Vistual Studio XML 智能提示

      开发中经常遇到要和各种各样的 XML 打交道,编辑 XML 文件时最头痛的便是要记住许多 XML 元素名称、属性名称。
      幸运的是,Vistual Studio 的 XML 智能提示功能可以大大地减轻这一痛苦。只需通过添加自定义的 XSD 文件使得在编辑 XML 文件时获得V ......

C#中用XmlTextReader对象操作XML文件

sd.xml文件:
<?xml version="1.0" encoding="gb2312"?>
<!--这是一个xml文件-->
<xml1>
  <item name="1">第一个item</item>
  <item name="2">
      <item name="1">这个结点(1) ......

在XML里写SQL语句(把SQL语句写进XML里)

你知道XML文件吧?(不知道的GOOGLE去!)那你听说过在XML里书写SQL语句吗?换句话说,把你的项目里所有SQL语句存储在XML文件里,你听说过吗?你做过吗?
我头次听说是小艾告诉我的,我敢肯定他是个这方面的高手,呵呵(赞一个,到此为止!)
那给你展示一下,在XML里书写SQL语句吧
<commands>
  <comman ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号