importdata.cs

来自「列车时刻查询Visual Studio 2005 + sql2005」· CS 代码 · 共 46 行

CS
46
字号
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;
			}
		}

	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?