XML转成dataset
1 public static DataSet CXmlToDataSet(string xmlStr) 2 { 3 if (!string.IsNullOrEmpty(xmlStr)) 4 { 5 StringReader StrStream = null; 6 XmlTextReader Xmlrdr = null; 7 try 8 { 9 DataSet ds = new DataSet(); 10 //读取字符串中的信息 11 StrStream = new StringReader(xmlStr); 12 //获取StrStream中的数据 13 Xmlrdr = new XmlTextReader(StrStream); 14 //ds获取Xmlrdr中的数据 15 ds.ReadXml(Xmlrdr); 16 return ds; 17 } 18 catch (Exception e) 19 { 20 throw e; 21 } 22 finally 23 { 24 //释放资源 25 if (Xmlrdr != null) 26 { 27 Xmlrdr.Close(); 28 StrStream.Close(); 29 StrStream.Dispose(); 30 } 31 } 32 } 33 else 34 { 35 return null; 36 } 37 }