andy_tigger

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::


 

///   <summary>
///   将指定DataTable转换为其等效的Xml流形式。
///   </summary>
///   <param   name= "table "> DataTable对象 </param>
///   <returns> </returns>
public   string   ToXmlString(DataTable   table)
{
if(table   ==   null)
{
return   null;
}

StringBuilder   content   =   new   StringBuilder();
StringWriter   writer   =   new   StringWriter(content);
XmlTextWriter   xmlWriter   =   new   XmlTextWriter(writer);

try
{
DataSet   ds   =   new   DataSet();
ds.Tables.Add(table.Copy());
ds.WriteXml(xmlWriter);

return   content.ToString();
}
finally
{
writer.Close();
xmlWriter.Close();
}
}

///   <summary>
///   将指定的Xml流转换为其等效的DataSet对象。
///   </summary>
///   <param   name= "xmlStream "> Xml流 </param>
///   <returns> </returns>
public   DataSet   ToDataSet(string   xmlStream)
{
if(xmlStream   ==   null   ||   xmlStream.Trim().Length   ==   0)
{
return   null;
}

StringReader   reader   =   new   StringReader(xmlStream);
XmlTextReader   xmlReader   =   new   XmlTextReader(reader);
try
{
DataSet   ds   =   new   DataSet();
ds.ReadXml(xmlReader);
return   ds;
}
finally
{
reader.Close();
xmlReader.Close();
}
}
posted on 2010-11-19 12:20  andy_tigger  阅读(500)  评论(0编辑  收藏  举报