数据写入DataTable C# 2005

欢迎访问广告之家:http://www.adggs.com

string xml_path = Server.MapPath("../xml/");
        if (!Directory.Exists(xml_path))
        {
            return;
        }

        DataTable dt = new DataTable();
        DataColumn name_xml = new DataColumn("xml_name");
        DataColumn path_xml = new DataColumn("xml_path");
        DataColumn last_time = new DataColumn("last_time");

        dt.Columns.Add(name_xml);
        dt.Columns.Add(path_xml);
        dt.Columns.Add(last_time);

        DirectoryInfo MyDir = new DirectoryInfo(xml_path);
      
        foreach (System.IO.FileInfo MyFile in MyDir.GetFiles("*.xml"))
        {
            DataRow dr = dt.NewRow();
            String FName = MyFile.Name;
            DateTime file_lastTime = MyFile.LastWriteTime;
            dr["xml_name"] = FName;
            dr["xml_path"] = xml_path + FName;
            dr["last_time"] = file_lastTime;
            dt.Rows.Add(dr);
        }

        DataView view = dt.DefaultView;
        view.Sort = "last_time desc";
        this.GridView_info.DataSource = view;
        this.GridView_info.DataBind();

 

 

 

 

友情链接:遨游官方论坛:http://www.7v7.cn/?fromuid=177

原文地址:https://www.cnblogs.com/binlunia/p/11267784.html