private DataTable MakeTable )
{
//生成DataTable
System.Data.DataTable myDataTable = new DataTable "本地数据表");
DataColumn myDataColumn;
DataRow myDataRow;
//生成数据列 ID,商品名称,商品价格
myDataColumn = new DataColumn );
myDataColumn.DataType = System.Type.GetType "System.Int32");
myDataColumn.ColumnName = "ID";
myDataColumn.ReadOnly = true;
myDataColumn.Unique = true;
myDataTable.Columns.Add myDataColumn);
myDataColumn = new DataColumn );
myDataColumn.DataType = System.Type.GetType "System.String");
myDataColumn.ColumnName = "商品名称";
myDataTable.Columns.Add myDataColumn);
myDataColumn = new DataColumn );
myDataColumn.DataType =System.Type.GetType "System.Decimal");
myDataColumn.ColumnName = "商品价格";
myDataTable.Columns.Add myDataColumn);
//为数据表添加数据行
myDataRow = myDataTable.NewRow );
myDataRow["id"] = 1;
myDataRow["商品名称"] = "足球";
myDataRow["商品价格"] =57.5;
myDataTable.Rows.Add myDataRow);
myDataRow = myDataTable.NewRow );
myDataRow["id"] = 2;
myDataRow["商品名称"] = "篮球";
myDataRow["商品价格"] =64.5;
myDataTable.Rows.Add myDataRow);
myDataRow = myDataTable.NewRow );
myDataRow["id"] = 3;
myDataRow["商品名称"] = "网球";
myDataRow["商品价格"] =6.5;
myDataTable.Rows.Add myDataRow);
myDataRow = myDataTable.NewRow );
myDataRow["id"] = 4;
myDataRow["商品名称"] = "网球拍";
myDataRow["商品价格"] =388.5;
myDataTable.Rows.Add myDataRow);
//返回数据表
return myDataTable;
}
|