转自:http://www.cnblogs.com/rhodamine/archive/2006/07/05/443192.aspx
private void MakeTable(DataTable myTable){
// Create a DataTable. DataTable myTable = new DataTable("myTable");
// Create a DataColumn and set various properties.
DataColumn myColumn = new DataColumn();
myColumn.DataType = System.Type.GetType("System.Decimal");
myColumn.AllowDBNull = false;
myColumn.Caption = "Price";
myColumn.ColumnName = "Price";
myColumn.DefaultValue = 25;
// Add the column to the table.
myTable.Columns.Add(myColumn);
// Add 10 rows and set values.
DataRow myRow;
for(int i = 0; i < 10; i++){
myRow = myTable.NewRow(); myRow["Price"] = i + 1;
// Be sure to add the new row to the DataRowCollection.
myTable.Rows.Add(myRow);
}
}
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemDataDataTableClassTopic.htm