XML文件导入、导出到 DataSet
时间:2010-09-09 来源:quietwalk
//导出dataset数据到XML文件
//Author:Quietwalk
//2010-09-09
public bool ExportToXMl(DataSet ds, string strXMLPath)
{
//DirectoryInfo mobileDir = new DirectoryInfo(strXMLPath);
FileInfo XMLfile = new FileInfo(strXMLPath);
bool bReturnValue = false;
try
{
if (ds != null && ds.Tables.Count > 0 && XMLfile.Exists)
{
ds.WriteXml(strXMLPath, XmlWriteMode.WriteSchema);
bReturnValue = true;
}
}
catch(SqlCeException ex)
{
throw(ex);
}
return bReturnValue;
}
//XML 数据导入到 DataSet中
//Author:Quietwalk
//2010-09-09
public DataSet ImportFromXml(string fromPath)
{
FileInfo xmlFile = new FileInfo(fromPath);
DataSet dsXML =null;
if (xmlFile.Exists)
{
FileStream fsReadXml = new FileStream(fromPath, FileMode.Open);
XmlTextReader myXmlReader = new XmlTextReader(fsReadXml);
dsXML=new DataSet ();
dsXML.ReadXml(myXmlReader);
myXmlReader.Close();
}
return dsXML;
}