测试table数据 winfrom datagridview 点击标头数字排序的时候table 列类型要为数字类型

public DataTable GenerateData(int NoOfRecord)
{
DataTable tbl = new DataTable();
tbl.Columns.Add(new DataColumn("ID", Type.GetType("System.Int32")));
tbl.Columns.Add(new DataColumn("Food Name", Type.GetType("System.String")));
tbl.Columns.Add(new DataColumn("Delivery Date", Type.GetType("System.DateTime")));
tbl.Columns.Add(new DataColumn("Profit", Type.GetType("System.Decimal")));
tbl.Columns.Add(new DataColumn("Available", Type.GetType("System.Boolean")));
string[] StringArray = {
"Apple",
"Banana",
"Cake",
"Dim Sum",
"Egg",
"French Bread",
"Ginger",
"Halloumi cheese",
"Ice-cream",
"Jelly",
"Kiwi fruit",
"Lamb",
"Moon cake",
"Nachos",
"Orange",
"Peanet",
"Quail's egg",
"Raisins",
"Sea Salt",
"Tea",
"Vegetables",
"Water",
"Yoghurt",
"Zest"
};
Random rand = new Random();
for (int i = 1; i <= NoOfRecord; i++) {
DataRow dr = tbl.NewRow();
dr["ID"] = i;
dr["Food Name"] = StringArray[rand.Next(StringArray.Count)];
dr["Delivery Date"] = new System.DateTime(2010, 1, 1).AddDays(rand.Next(365));
dr["Profit"] = rand.NextDouble() * 100;
dr["Available"] = (rand.Next(2) == 1 ? true : false);
tbl.Rows.Add(dr);
}
return tbl;
}

上一篇:linux 查看文件夹下的文件个数(当前目录的文件数)//包含子目录


下一篇:java_web学习(四) Date的理解与应用