導入數據類,主要包括導入XML數據
using System;
using System.Data;
using System.Windows.Forms;
namespace train
...{
/**//// <summary>
/// ImportData :導入數據
/// </summary>
public class ImportData
...{
private DataSet ds;
private DataTable table;
public ImportData()
...{
ds=new DataSet();
table=new DataTable();
}
/**//// <summary>
/// 從XML文件導入數據
/// </summary>
/// <returns>返回包含數據的DataTable</returns>
public DataTable ImportDataFromXML()
...{
OpenFileDialog dialog=new OpenFileDialog();
dialog.Filter="XML文件|*.XML";
dialog.ShowDialog();
string path=dialog.FileName;
if(path.Length==0)
...{
return null;
}
try
...{
ds.ReadXml(@path,XMLReadMode.Auto);
return ds.Tables[0];
}
catch(Exception e)
...{
Console.WriteLine(e.Message);
return null;
}
}
}
}