Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
DataTable Constructor

DataTable Constructor

Initializes a new instance of the DataTable class with no arguments.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)

'Declaration
Public Sub New

The constructor sets initial values for all properties of the DataTable object. The following table shows the properties and their default values. When an instance of DataTable is created, the following read/write properties are set to initial values.

Property

Default value

CaseSensitive

Same as the parent DataSet, if it belongs to one. Otherwise, false.

DisplayExpression

Empty string ("")

Locale

Same as the parent DataSet object's CultureInfo (returned by the Locale property); if no parent exists, the default is the current system CultureInfo.

MinimumCapacity

50 rows.

You can change the value for any of these properties through a separate call to the property.

The following example creates a new DataTable with DataColumn and DataRow, and displays it in a DataGridView control.

Private Sub MakeDataTableAndDisplay()
   ' Create new DataTable. 
   Dim table As New DataTable

   ' 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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show:
© 2015 Microsoft