构造DATATABLE

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

posted on 2006-07-05 11:58  彭灿明  阅读(1084)  评论(1编辑  收藏  举报

导航