//动态生成DataTable
private DataTable CreateTable()
{
DataTable dt = new DataTable("dirName");
#region table column
DataColumn columnID = new DataColumn(); //创建一列
columnID.DataType = System.Type.GetType("System.Int32"); //数据类型
columnID.ColumnName = "ID"; //列名
columnID.AutoIncrement = true; //自动递增ID号
dt.Columns.Add(columnID); //添加到table
DataColumn columnName = new DataColumn();
columnName.DataType = System.Type.GetType("System.String");
columnName.ColumnName = "Name";
dt.Columns.Add(columnName);
DataColumn fullName = new DataColumn();
fullName.DataType = System.Type.GetType("System.String");
fullName.ColumnName = "fullName";
dt.Columns.Add(fullName);
DataColumn cTime = new DataColumn();
cTime.DataType = System.Type.GetType("System.String");
cTime.ColumnName = "CreateDate";
dt.Columns.Add(cTime);
DataColumn type = new DataColumn();
type.DataType = System.Type.GetType("System.String");
type.ColumnName = "type";
dt.Columns.Add(type);
DataColumn exName = new DataColumn();
exName.DataType = System.Type.GetType("System.String");
exName.ColumnName = "exName";
dt.Columns.Add(exName);
DataColumn size = new DataColumn();
size.DataType = System.Type.GetType("System.Int32");
size.ColumnName = "size";
dt.Columns.Add(size);
#endregion
//设置主键
DataColumn[] keys = new DataColumn[1];
keys[0] = columnID;
dt.PrimaryKey = keys;
for (int i = 0; i < 3; i++)
{
DataRow row;
row = dt.NewRow();
row["Name"] = "陈yu**";
row["fullName"] = "陈**";
row["exName"] = "";
row["CreateDate"] = System.DateTime.Now.ToShortDateString();
row["type"] = "1";
row["size"] = 0;
dt.Rows.Add(row);
}
return dt;
}