温故而知新这句话很有道理,但是做到温故的人可不多,况且即使你想温故如果没有将以前的东西记录下来你也没法去温故,所以坚持记录我觉得很重要。百度上都可以找到的其实
添加引用
using System;
using System.Data;
using System.IO;
using System.Text;
using System.Xml;
private string ConvertDataTableToXML(DataTable xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
{
stream = new MemoryStream();
//根据stream实例化writer
writer = new XmlTextWriter(stream, Encoding.Default);
//获取 xmlDS中的数据
xmlDS.WriteXml(writer);
int count = (int)stream.Length;
byte[] arr = new byte[count];
//定位流开始位置
stream.Seek(0, SeekOrigin.Begin);
stream.Read(arr, 0, count);
//utf8编码格式
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();
}
}