.NET实现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();

}

}

以上就是.NET实现XML与DataTable互转的实例代码。没有不会淡的疤,没有不会好的伤,没有不会停下来的绝望,时间不仅让你看透别人,也让你认清自己。更多关于.NET实现XML与DataTable互转的实例代码请关注haodaima.com其它相关文章!

标签: NET XML