public static string DataTableToXml(DataTable dt)
{
System.IO.TextWriter tw = new System.IO.StringWriter();
dt.TableName = dt.TableName.Length == 0 ? "TableName" : dt.TableName;
dt.WriteXml(tw);
dt.WriteXmlSchema(tw);
return tw.ToString();
}
public static DataTable XmlToDataDable(string xml)
{
System.IO.TextReader trDataTable = new System.IO.StringReader(xml.Substring(0, xml.IndexOf("<?xml")));
System.IO.TextReader trSchema = new System.IO.StringReader(xml.Substring(xml.IndexOf("<?xml")));
DataTable dt = new DataTable();
dt.ReadXmlSchema(trSchema);
dt.ReadXml(trDataTable);
return dt;
}
C#DataTable和XML互转
最新推荐文章于 2023-11-28 08:58:09 发布