土豆烧牛肉

导航

 

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;
}

posted on 2013-12-26 16:38  土豆烧牛肉  阅读(157)  评论(0编辑  收藏  举报