DataTable Constructor (String)
.NET Framework (current version)
Initializes a new instance of the DataTable class with the specified table name.
Assembly: System.Data (in System.Data.dll)
Parameters
- tableName
-
Type:
System.String
The name to give the table. If tableName is null or an empty string, a default name is given when added to the DataTableCollection.
The following example creates a DataTable and displays it in a DataGridView control.
Private Sub MakeDataTableAndDisplay() ' Create new DataTable. Dim table As DataTable = New DataTable("table") ' Declare DataColumn and DataRow variables. Dim column As DataColumn Dim row As DataRow ' Create new DataColumn, set DataType, ' ColumnName and add to DataTable. column = New DataColumn column.DataType = System.Type.GetType("System.Int32") column.ColumnName = "id" table.Columns.Add(column) ' Create second column. column = New DataColumn column.DataType = Type.GetType("System.String") column.ColumnName = "item" table.Columns.Add(column) ' Create new DataRow objects and add to DataTable. Dim i As Integer For i = 0 To 10 row = table.NewRow row("id") = i row("item") = "item " & i table.Rows.Add(row) Next i ' Set to DataGrid.DataSource property to the table. DataGrid1.DataSource = table End Sub
.NET Framework
Available since 1.1
Available since 1.1
Show: