列车时刻查询系统(北大青鸟大二寒假作业) 源代码(七)



导入数据类,主要包括导入XML数据

 

 

using  System;
using  System.Data;
using  System.Windows.Forms;
namespace  train
{
    
/// 
    
/// ImportData :导入数据
    
/// 

    public class ImportData
    
{
        
private DataSet ds;
        
private DataTable table;
        
public ImportData()
        
{
            ds
=new DataSet();
            table
=new DataTable();
        }

        
/// 
        
/// 从XML文件导入数据
        
/// 

        
/// 返回包含数据的DataTable

        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;
            }

        }


    }

}

 

你可能感兴趣的:(java~爪哇)