.NET实现XML与DataTable互转的实例代码_asp.net教程-查字典教程网
.NET实现XML与DataTable互转的实例代码
.NET实现XML与DataTable互转的实例代码
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:privatestringConvertDataTableToXML(DataTablexmlDS){MemoryStre...

复制代码 代码如下:

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();

}

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新asp.net教程学习
    热门asp.net教程学习
    编程开发子分类