DataTable Constructors
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Initialiseert een nieuw exemplaar van de DataTable klasse.
Overloads
| Name | Description |
|---|---|
| DataTable() |
Initialiseert een nieuw exemplaar van de DataTable klasse zonder argumenten. |
| DataTable(String) |
Initialiseert een nieuw exemplaar van de DataTable klasse met de opgegeven tabelnaam. |
| DataTable(SerializationInfo, StreamingContext) |
Initialiseert een nieuw exemplaar van de DataTable klasse met geserialiseerde gegevens. |
| DataTable(String, String) |
Initialiseert een nieuw exemplaar van de DataTable klasse met behulp van de opgegeven tabelnaam en naamruimte. |
DataTable()
Initialiseert een nieuw exemplaar van de DataTable klasse zonder argumenten.
public:
DataTable();
public DataTable();
Public Sub New ()
Voorbeelden
In het volgende voorbeeld wordt een nieuw DataTable bestand gemaakt met DataColumn en DataRow, en weergegeven in een DataGridView besturingselement.
private void MakeDataTableAndDisplay()
{
// Create new DataTable.
DataTable table = new DataTable();
// Declare DataColumn and DataRow variables.
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType, ColumnName
// and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "item";
table.Columns.Add(column);
// Create new DataRow objects and add to DataTable.
for(int i = 0; i < 10; i++)
{
row = table.NewRow();
row["id"] = i;
row["item"] = "item " + i;
table.Rows.Add(row);
}
// Set to DataGrid.DataSource property to the table.
dataGrid1.DataSource = table;
}
Private Sub MakeDataTableAndDisplay()
' Create new DataTable.
Dim table As New DataTable
' Declare DataColumn and DataRow variables.
Dim column As DataColumn
Dim row As DataRow
' Create new DataColumn, set DataType, ColumnName
' and add to DataTable.
column = New DataColumn
column.DataType = System.Type.GetType("System.Int32")
column.ColumnName = "id"
table.Columns.Add(column)
' Create second column.
column = New DataColumn
column.DataType = Type.GetType("System.String")
column.ColumnName = "item"
table.Columns.Add(column)
' Create new DataRow objects and add to DataTable.
Dim i As Integer
For i = 0 To 10
row = table.NewRow
row("id") = i
row("item") = "item " & i
table.Rows.Add(row)
Next i
' Set to DataGrid.DataSource property to the table.
DataGrid1.DataSource = table
End Sub
Opmerkingen
De constructor stelt initiële waarden in voor alle eigenschappen van het DataTable object. In de volgende tabel ziet u de eigenschappen en de bijbehorende standaardwaarden. Wanneer een exemplaar van DataTable wordt gemaakt, worden de volgende eigenschappen voor lezen/schrijven ingesteld op initiële waarden.
| Property | Standaardwaarde |
|---|---|
| CaseSensitive | Hetzelfde als het bovenliggende DataSetitem, als het tot een behoort. Anders false. |
| DisplayExpression | Lege tekenreeks ("") |
| Locale | Hetzelfde als het bovenliggende DataSet object (geretourneerd door de Locale eigenschap); als er geen bovenliggend object CultureInfo bestaat, is de standaardwaarde het huidige systeemCultureInfo. |
| Minimumcapaciteit | 50 rijen. |
U kunt de waarde voor een van deze eigenschappen wijzigen via een afzonderlijke aanroep naar de eigenschap.
Zie ook
Van toepassing op
DataTable(String)
Initialiseert een nieuw exemplaar van de DataTable klasse met de opgegeven tabelnaam.
public:
DataTable(System::String ^ tableName);
public DataTable(string tableName);
new System.Data.DataTable : string -> System.Data.DataTable
Public Sub New (tableName As String)
Parameters
- tableName
- String
De naam die de tabel moet geven. Als tableName dit een of een lege tekenreeks is null , wordt er een standaardnaam gegeven wanneer deze wordt toegevoegd aan de DataTableCollection.
Voorbeelden
In het volgende voorbeeld wordt een en DataTable weergegeven in een DataGridView besturingselement.
private void MakeDataTableAndDisplay()
{
// Create new DataTable.
DataTable table = new DataTable("table");
// Declare DataColumn and DataRow variables.
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType,
// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "item";
table.Columns.Add(column);
// Create new DataRow objects and add to DataTable.
for(int i = 0; i < 10; i++)
{
row = table.NewRow();
row["id"] = i;
row["item"] = "item " + i;
table.Rows.Add(row);
}
// Set to DataGrid.DataSource property to the table.
dataGrid1.DataSource = table;
}
Private Sub MakeDataTableAndDisplay()
' Create new DataTable.
Dim table As New DataTable("table")
' Declare DataColumn and DataRow variables.
Dim column As DataColumn
Dim row As DataRow
' Create new DataColumn, set DataType,
' ColumnName and add to DataTable.
column = New DataColumn
column.DataType = System.Type.GetType("System.Int32")
column.ColumnName = "id"
table.Columns.Add(column)
' Create second column.
column = New DataColumn
column.DataType = Type.GetType("System.String")
column.ColumnName = "item"
table.Columns.Add(column)
' Create new DataRow objects and add to DataTable.
Dim i As Integer
For i = 0 To 10
row = table.NewRow
row("id") = i
row("item") = "item " & i
table.Rows.Add(row)
Next i
' Set to DataGrid.DataSource property to the table.
DataGrid1.DataSource = table
End Sub
Zie ook
Van toepassing op
DataTable(SerializationInfo, StreamingContext)
Initialiseert een nieuw exemplaar van de DataTable klasse met geserialiseerde gegevens.
protected:
DataTable(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected DataTable(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Data.DataTable : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Data.DataTable
Protected Sub New (info As SerializationInfo, context As StreamingContext)
Parameters
- info
- SerializationInfo
De geserialiseerde gegevens voor de gegevensset.
- context
- StreamingContext
Contextuele informatie over de geserialiseerde stroom.
Uitzonderingen
alleen .NET 7 en latere versies: info bevat binaire gegevens.
Opmerkingen
Deze implementatie van de DataTable constructor is vereist voor ISerializable.
Zie ook
Van toepassing op
DataTable(String, String)
Initialiseert een nieuw exemplaar van de DataTable klasse met behulp van de opgegeven tabelnaam en naamruimte.
public:
DataTable(System::String ^ tableName, System::String ^ tableNamespace);
public DataTable(string tableName, string tableNamespace);
new System.Data.DataTable : string * string -> System.Data.DataTable
Public Sub New (tableName As String, tableNamespace As String)
Parameters
- tableName
- String
De naam die de tabel moet geven. Als tableName dit een of een lege tekenreeks is null , wordt er een standaardnaam gegeven wanneer deze wordt toegevoegd aan de DataTableCollection.
- tableNamespace
- String
De naamruimte voor de XML-weergave van de gegevens die zijn opgeslagen in de DataTable.