文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C#实现XML与DataTable互转

C#实现XML与DataTable互转

时间:2011-04-14  来源:June拼搏

C#中XML与datatable互换的两个函数:

    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();
}
}
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载