Initializes a new instance of the DataTable class with no arguments.
[Visual Basic] Overloads Public Sub New() [C#] public DataTable(); [C++] public: DataTable(); [JScript] public function DataTable();
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 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 | 25 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 System.WinForms.DataGrid control.
[Visual Basic]
Private Sub MakeDataTableAndDisplay() ' Create new DataTable and DataSource objects. Dim myDataTable As New DataTable Dim myDataSource As New DataSource ' 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 = "thing" 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(0) = i myDataRow(1) = "thing " & i myDataTable.Rows.Add myDataRow Next i ' Configure DataSource and set to DataGrid.DataSource property. myDataSource.Table = myDataTable myDataSource.Begin DataGrid1.DataSource = myDataSource DataGrid1.PopulateColumns End Sub
DataTable Class | DataTable Members | System.Data Namespace | DataTable Constructor Overload List | DataColumn | DataRow | DataView