.NET Framework class library
DataTable constructor ()
No parameters initialize a new instance of the DataTable class.
[Visual Basic]
Public Sub New ()
[C #]
Public dataatable ();
[C ]
PUBLIC: DATATABLE ();
[Jscript]
Public function data ();
Note
The constructor sets the initial value for all attributes of the DataTable object. The following table shows these properties and their default values. When a DataTable instance is created, the following read / write properties will be set to the initial value.
Property Default Value Case Size If it belongs to one, the same is the same as the parent DataSet. Otherwise, False. The display expression empty string ("") area setting is the same as the CultureInfo of the parent DataSet object; if there is no parent object, the CultureInfo of the current system is default. Minimum capacity 25 lines.
You can change any of these attribute values by a separate call attribute.
Example
[Visual Basic, C #, C ] The following example creates a new DataTable with Datacolumn and DataRow and displays it in the DataGrid control.
[Visual Basic]
Private sub makeDataTableAndDisplay ()
'CREATE New DataTable.
DIM MyDataTable As New DataTable
'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 = "item"
MyDataTable.columns.add (MyDatacolumn)
'CREATE New DataRow Objects and Add to DataTable.
DIM I as integer
For i = 0 TO 10
mydatarow = myDataBLE.NEWROW
MyDATAROW ("ID") = i
MyDATAROW ("item") = "item" & i
MyDataTable.Rows.Add (MyDataRow)
Next I
'Set to datagrid.datasource property to the table.
DataGrid1.datasource = MyDATABLE
End Sub
[C #]
Private void makeDataTableAndDisplay () {// CREATE New DataTable.
DataTable myDataTable = new dataatable ();
// Declare Datacolumn and DataRow Variables.
Datacolumn mydatacolumn;
DataRow MyDataRow;
// Create New Datacolumn, Set DataType, ColumnName and Add to DataBole.
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 = "item";
MyDataTable.columns.add (MyDatacolumn);
// CREATE New DataRow Objects and add to dataable.
For (int i = 0; i <10; i ) {
mydatarow = myDataBLE.NEWROW ();
MyDataRow ["ID"] = i;
MyDataRow ["item"] = "item" i;
MyDataTable.Rows.Add (MyDATAROW);
}
// set to datagrid.datasource property to the table.
DataGrid1.datasource = MyDataTable;
}
[C ]
Private:
Void makeDataTableAndDisplay () {
// CREATE New DataTable.
DataTable * mydataable = new data ();
// Declare Datacolumn and DataRow Variables.
Datacolumn * mydatacolumn;
DataRow * mydatarow;
// Create New Datacolumn, Set DataType, ColumnName and Add to DataBole.
MyDatacolumn = new datacolumn ();
MyDataColumn-> DataType = system :: type :: gettype (s "system.int32");
MyDataColumn-> columnname = s "id";
MyDataTable-> columns-> add (mydatacolumn);
// CREATE Second Column.
MyDatacolumn = new datacolumn ();
MyDataColumn-> DataType = type :: gettype (s "system.sw");
MyDataColumn-> columnname = s "item"; mydataable-> columns-> add (myDatacolumn);
// CREATE New DataRow Objects and add to dataable.
For (int i = 0; i <10; i ) {
MyDATAROW = myDataBLE-> newrow ();
MyDATAROW-> Item [S "ID"] = __box (i);
MyDATAROW-> item [s "item"] = string :: format (s "item {0}", __box (i));
MyDataTable-> rows-> add (myDATAROW);
}
// set to datagrid.datasource property to the table.
DataGrid1-> DataSource = mydataable;
}
[JScript] There is no example available for JScript. To view Visual Basic, C # or C examples, click the "Language Filter" button in the upper left corner.
Claim
Platform: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 Series, .NET Framework Lite
See
DataTable Class | DataTable Member | System.Data Namespace | DataTable Construction Function Overload List | Datacolumn | DataRow | DataView