System.Data Namespace DataTable Class
Intitalizes a new instance of the DataTable class with the specified table name.
[ VB ]
Public Sub New ( _
ByVal tableName As String _
)
[ C# ]
public DataTable (
String tableName
);
[ C++ ]
public: DataTable (
String* tableName
);
[ JScript ]
public function DataTable (
tableName : String
);
- tableName
- The name to give the table. If a null reference or an empty string, a default name will be given when added to the DataTableCollection.
The following example initializes a DataTable with a given table name.
Private void DataTableDemo ( ) {
// create new DataTable.
DataTable myDataTable = new DataTable ( "myDataTable" );
// declare DataColumn and DataRow variables.
DataColumn myDataColumn;
DataRow myDataRow;
// 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 new DataRow objects and add to DataTable.
for ( int i = 0; i < 10; i++ ) {
myDataRow = myDataTable.NewRow ( );
myDataRow [ "id" ] = i;
myDataRow [ "item" ] = "item " + i;
myDataTable.Rows.Add ( myDataRow );
}
}
Private Sub DataTableDemo ( )
' create new DataTable.
Dim myDataTable As DataTable = New DataTable ( "myDataTable" )
' 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 new DataRow objects and add to DataTable.
Dim i As Integer
For i = 0 To 10
myDataRow = myDataTable.NewRow
myDataRow ( "id" ) = i
myDataRow ( "item" ) = "item " & i
myDataTable.Rows.Add ( myDataRow )
Next i
End Sub |
|
C# |
VB |
DataTable Members DataTable Constructor Overload List DataColumn DataRow DataView