示例 private sub makedatatableanddisplay() ' create new datatable. dim mydatatable as new datatable
dim mydatatable as datatable = new datatable("mydatatable")
' declare datacolumn and datarow variables. dim mydatacolumn as datacolumn dim mydatarow as datarow
' create new datacolumn, set datatype, columnname and add to datatable. mydatacolumn = new datacolumn mydatacolumn.datatype = system.type.gettype("system.int32") mydatacolumn.columnname = "id" mydatatable.columns.add(mydatacolumn)
' create second column. mydatacolumn = new datacolumn mydatacolumn.datatype = type.gettype("system.string") mydatacolumn.columnname = "item" mydatatable.columns.add(mydatacolumn)
' create new datarow objects and add to datatable. dim i as integer for i = 0 to 10 mydatarow = mydatatable.newrow mydatarow("id") = i mydatarow("item") = "item " & i mydatatable.rows.add(mydatarow) next i
' set to datagrid.datasource property to the table. datagrid1.datasource = mydatatable end sub