NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

DataTable Constructor

Initializes a new instance of the DataTable class.

Overload List

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();

Intitalizes a new instance of the DataTable class with the specified table name.

[Visual Basic] Overloads Public Sub New(String)
[C#] public DataTable(String);
[C++] public: DataTable(String*);
[JScript] public function DataTable(String);

Example [Visual Basic]

The following example creates a System.WinForms.DataGridTable and displays it in a System.WinForms.DataGrid control.

Note   This example shows how to use one of the overloaded version of the DataTable constructor. For other examples that may be available, see the individual overload topics.

[Visual Basic]

Private Sub MakeDataTableAndDisplay()
   ' Create new DataTable and DataSource objects.
   Dim myDataTable As DataTable
   myDataTable = New DataTable("SampleDataTable")
   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

See Also

DataTable Class | DataTable Members | System.Data Namespace