XML字符串转DataSet
public static DataSet XmlToDataSet(string strXml)
{
DataSet ds = new DataSet();
StringReader sr = new StringReader(strXml);
XmlTextReader xmlReader = new XmlTextReader(sr);
ds.ReadXml(xmlReader);
return ds;
}XML文件转DataSet
public static DataSet GetDataSetByXml(string strXmlPath)
{
try
{
DataSet ds = new DataSet();
ds.ReadXml(strXmlPath); //从文件中读取XML到DataSet
if (ds.Tables.Count > 0)
{
return ds;
}
return null;
}
catch (Exception)
{
return null;
}
}
本文介绍两种将XML数据转换为DataSet的方法:一种是从XML字符串转换,另一种是从XML文件转换。这两种方法都使用了System.Xml命名空间下的类来实现。
1万+

被折叠的 条评论
为什么被折叠?



