溫故而知新這句話很有道理,但是做到溫故的人可不多,況且即使你想溫故如果沒有將以前的東西記錄下來你也沒法去溫故,所以堅持記錄我覺得很重要。百度上都可以找到的其實
添加引用
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();
}
}