Creates a new DataRow with the same schema as the table.
[Visual Basic] Public Function NewRow() As DataRow [C#] public DataRow NewRow(); [C++] public: DataRow* NewRow(); [JScript] public function NewRow() : DataRow;
A DataRow with the same schema as the DataTable.
You must use the NewRow method to create new DataRow objects with the same schema as the DataTable. After creating a DataRow, you can add it to the RowsCollection, through the DataTable object's Rows property.
The following example creates a DataTable, adds two DataColumn objects that determine the table's schema, and creates several new DataRow objects using the NewRow method. Those DataRow objects are then added to the RowsCollection using the Add method.
[Visual Basic]
Private Sub MakeDataTableAndDisplay() ' Create new DataTable and DataSource objects. Dim myDataTable As New DataTable ' Declare DataColumn and DataRow variables. Dim myDataColumn As DataColumn Dim myDataRow As DataRow Dim dv As DataView ' 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. dv = New DataView(myDataTable) dv.Begin DataGrid1.DataSource = dv DataGrid1.PopulateColumns End Sub
DataTable Class | DataTable Members | System.Data Namespace | AcceptChanges | Add | ColumnsCollection | DataColumn | RowsCollection