/// <summary> /// DataTable-------------------->XML --String /// </summary> public static String ToXmlString(DataTable dt) { StringWriter tr = new StringWriter(); try { dt.WriteXml(tr); return tr.ToString(); } catch { throw; } finally { tr.Dispose(); } } /// <summary> /// DataSet----------------->XML---String /// </summary> public static String ToXmlString(DataSet ds) { StringWriter tr = new StringWriter(); try { ds.WriteXml(tr, XmlWriteMode.IgnoreSchema); return tr.ToString(); } catch { throw; } finally { tr.Dispose(); } } /// <summary> /// xml转换为数据集 /// </summary> public static DataSet XmlToDataSet(string xml) { try { StringReader sr = new StringReader(xml); DataSet ds = new DataSet(); ds.ReadXml(sr); return ds; } catch { throw; } } /// <summary> /// Xml转换为数据表 /// </summary> public static DataTable ToDataTable(string xmlData, int TableIndex) { try { return XmlToDataSet(xmlData).Tables[TableIndex]; } catch { throw; } }