DataTable Konstruktoren
Definition
Überlädt
DataTable() |
Initialisiert eine neue Instanz der DataTable-Klasse ohne Argumente.Initializes a new instance of the DataTable class with no arguments. |
DataTable(String) |
Initialisiert eine neue Instanz der DataTable-Klasse mit dem angegebenen Tabellennamen.Initializes a new instance of the DataTable class with the specified table name. |
DataTable(SerializationInfo, StreamingContext) |
Initialisiert eine neue Instanz der DataTable-Klasse mit der SerializationInfo und dem StreamingContext.Initializes a new instance of the DataTable class with the SerializationInfo and the StreamingContext. |
DataTable(String, String) |
Initialisiert eine neue Instanz der DataTable-Klasse mit dem angegebenen Tabellennamen und Namespace.Initializes a new instance of the DataTable class using the specified table name and namespace. |
DataTable()
Initialisiert eine neue Instanz der DataTable-Klasse ohne Argumente.Initializes a new instance of the DataTable class with no arguments.
public:
DataTable();
public DataTable ();
Public Sub New ()
Beispiele
Im folgenden Beispiel wird ein neues DataTable mit DataColumn und DataRowerstellt und in einem DataGridView -Steuerelement angezeigt.The following example creates a new DataTable with DataColumn and DataRow, and displays it in a DataGridView control.
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
Hinweise
Der-Konstruktor legt die Anfangswerte für alle Eigenschaften DataTable des-Objekts fest.The constructor sets initial values for all properties of the DataTable object. In der folgenden Tabelle werden die Eigenschaften und deren Standardwerte angezeigt.The following table shows the properties and their default values. Wenn eine Instanz von DataTable erstellt wird, werden die folgenden Lese-/Schreibeigenschaften auf Anfangswerte festgelegt.When an instance of DataTable is created, the following read/write properties are set to initial values.
EigenschaftProperty | StandardwertDefault value |
---|---|
CaseSensitiveCaseSensitive | Identisch mit dem über DataSetgeordneten, wenn es zu einem gehört.Same as the parent DataSet, if it belongs to one. Andernfalls false .Otherwise, false . |
DisplayExpressionDisplayExpression | leere Zeichenfolge ("")Empty string ("") |
LocaleLocale | Identisch mit dem des DataSet übergeordneten CultureInfo Objekts (von der Locale -Eigenschaft zurückgegeben); Wenn kein übergeordnetes Element vorhanden ist, CultureInfoist der Standardwert das aktuelle System.Same as the parent DataSet object's CultureInfo (returned by the Locale property); if no parent exists, the default is the current system CultureInfo. |
MinimumCapacityMinimumCapacity | 50 Zeilen.50 rows. |
Sie können den Wert für jede dieser Eigenschaften durch einen separaten aufrufsbefehl ändern.You can change the value for any of these properties through a separate call to the property.
Siehe auch
DataTable(String)
Initialisiert eine neue Instanz der DataTable-Klasse mit dem angegebenen Tabellennamen.Initializes a new instance of the DataTable class with the specified table name.
public:
DataTable(System::String ^ tableName);
public DataTable (string tableName);
new System.Data.DataTable : string -> System.Data.DataTable
Public Sub New (tableName As String)
Parameter
- tableName
- String
Der Name, der der Tabelle gegeben werden soll.The name to give the table. Wenn tableName
null
oder eine leere Zeichenfolge ist, wird beim Hinzufügen zur DataTableCollection ein Standardname vergeben.If tableName
is null
or an empty string, a default name is given when added to the DataTableCollection.
Beispiele
Im folgenden Beispiel wird ein DataTable -Element erstellt, das DataGridView in einem-Steuerelement angezeigt wird.The following example creates a DataTable and displays it in a DataGridView control.
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
Siehe auch
DataTable(SerializationInfo, StreamingContext)
Initialisiert eine neue Instanz der DataTable-Klasse mit der SerializationInfo und dem StreamingContext.Initializes a new instance of the DataTable class with the SerializationInfo and the StreamingContext.
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)
Parameter
- info
- SerializationInfo
Die zum Serialisieren bzw. Deserialisieren eines Objekts benötigten Daten.The data needed to serialize or deserialize an object.
- context
- StreamingContext
Die Quelle und das Ziel eines angegebenen serialisierten Streams.The source and destination of a given serialized stream.
Hinweise
Diese Implementierung des DataTable Konstruktors ist für ISerializableerforderlich.This implementation of the DataTable constructor is required for ISerializable.
Siehe auch
DataTable(String, String)
Initialisiert eine neue Instanz der DataTable-Klasse mit dem angegebenen Tabellennamen und Namespace.Initializes a new instance of the DataTable class using the specified table name and namespace.
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)
Parameter
- tableName
- String
Der Name, der der Tabelle gegeben werden soll.The name to give the table. Wenn tableName
null
oder eine leere Zeichenfolge ist, wird beim Hinzufügen zur DataTableCollection ein Standardname vergeben.If tableName
is null
or an empty string, a default name is given when added to the DataTableCollection.
- tableNamespace
- String
Der Namespace für die XML-Darstellung der in der DataTable
gespeicherten Daten.The namespace for the XML representation of the data stored in the DataTable
.