数据写入DataTable C# 2005

2008年12月9日星期二

数据写入DataTable C# 2005

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();

      0 评论:

      发表评论