[ASP.NET][C#][System.Data]建立/Create DataTable

  • 1642
  • 0

.

//Create a DataTable.
DataTable dtFiles = new DataTable();
dtFiles.Columns.AddRange(new DataColumn[4] { new DataColumn("SN", typeof(int)),
										new DataColumn("Name", typeof(string)),
										new DataColumn("Size", typeof(decimal)),
										new DataColumn("Date", typeof(string))});

//Append Data Row
int iSN = 1;
string sDateTime = "02-01-18  10:51AM";
decimal dSize = decimal.Parse(4129) / 1024;
string sFileName = "abc.txt";

dtFiles.Rows.Add();
dtFiles.Rows[0]["SN"] = iSN;
dtFiles.Rows[0]["Date"] = sDateTime;
dtFiles.Rows[0]["Size"] = dSize;
dtFiles.Rows[0]["Name"] = sFileName;


iSN = 2;
sDateTime = "02-01-19  10:52AM";
dSize = decimal.Parse(3010) / 1024;
sFileName = "def.txt";

dtFiles.Rows.Add();
dtFiles.Rows[1]["SN"] = iSN;
dtFiles.Rows[1]["Date"] = sDateTime;
dtFiles.Rows[1]["Size"] = dSize;
dtFiles.Rows[1]["Name"] = sFileName;