讀取XML檔案到DataSet示例
阿新 • • 發佈:2018-11-19
/// <summary>
/// 讀取XML檔案
/// </summary>
/// <param name="fileName"></param>
public string TestReadXMLFile(string fileName)
{
try
{
DataSet objDataSet = new DataSet();
string filepath = System.Web.HttpContext.Current.Server.MapPath("~/CatitalXML");
objDataSet.ReadXml(filepath + "/" + fileName + ".XML");
//第一種方式 //dgEmployees.DataSource = objDataSet; //dgEmployees.DataBind();
//第二種方式 //dgEmployees.DataSource = objDataSet.Tables["Ad"].DefaultView; //dgEmployees.DataBind(); return "成功"; } catch (Exception ex) { return "失敗"; } }
//第一種方式 //dgEmployees.DataSource = objDataSet; //dgEmployees.DataBind();
//第二種方式 //dgEmployees.DataSource = objDataSet.Tables["Ad"].DefaultView; //dgEmployees.DataBind(); return "成功"; } catch (Exception ex) { return "失敗"; } }