DataTable Конструкторы
Определение
Перегрузки
DataTable() |
Инициализирует новый экземпляр класса DataTable, не передавая ему никаких аргументов.Initializes a new instance of the DataTable class with no arguments. |
DataTable(String) |
Инициализирует новый экземпляр класса DataTable с указанным именем таблицы.Initializes a new instance of the DataTable class with the specified table name. |
DataTable(SerializationInfo, StreamingContext) |
Инициализирует новый экземпляр класса DataTable со свойствами SerializationInfo и StreamingContext.Initializes a new instance of the DataTable class with the SerializationInfo and the StreamingContext. |
DataTable(String, String) |
Инициализирует новый экземпляр класса DataTable с заданными именем таблицы и пространством имен.Initializes a new instance of the DataTable class using the specified table name and namespace. |
DataTable()
public:
DataTable();
public DataTable ();
Public Sub New ()
Примеры
В следующем примере создается новый DataTable с помощью DataColumn и DataRow , и он отображается в DataGridView элементе управления.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
Комментарии
Конструктор задает начальные значения для всех свойств DataTable объекта.The constructor sets initial values for all properties of the DataTable object. В следующей таблице показаны свойства и их значения по умолчанию.The following table shows the properties and their default values. Когда DataTable создается экземпляр, для следующих свойств чтения и записи устанавливаются начальные значения.When an instance of DataTable is created, the following read/write properties are set to initial values.
СвойствоProperty | Значение по умолчаниюDefault value |
---|---|
CaseSensitiveCaseSensitive | То же, что и у родителя DataSet , если он принадлежит к одному.Same as the parent DataSet, if it belongs to one. В противном случае — значение false .Otherwise, false . |
дисплайекспрессионDisplayExpression | Пустая строка ("")Empty string ("") |
ЛокальLocale | То же, что и родительский DataSet объект CultureInfo (возвращаемый Locale свойством); если родительский элемент не существует, по умолчанию используется текущая система CultureInfo .Same as the parent DataSet object's CultureInfo (returned by the Locale property); if no parent exists, the default is the current system CultureInfo. |
минимумкапаЦитиMinimumCapacity | 50 строк.50 rows. |
Значение любого из этих свойств можно изменить с помощью отдельного вызова свойства.You can change the value for any of these properties through a separate call to the property.
См. также раздел
Применяется к
DataTable(String)
public:
DataTable(System::String ^ tableName);
public DataTable (string? tableName);
public DataTable (string tableName);
new System.Data.DataTable : string -> System.Data.DataTable
Public Sub New (tableName As String)
Параметры
- tableName
- String
Имя, задаваемое таблице.The name to give the table. Если значение параметра tableName
— null
или пустая строка, имя по умолчанию присваивается при добавлении в коллекцию DataTableCollection.If tableName
is null
or an empty string, a default name is given when added to the DataTableCollection.
Примеры
В следующем примере создается DataTable и отображается в DataGridView элементе управления.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
См. также раздел
Применяется к
DataTable(SerializationInfo, StreamingContext)
Инициализирует новый экземпляр класса DataTable со свойствами SerializationInfo и 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)
Параметры
- info
- SerializationInfo
Информация, необходимая для сериализации или десериализации объекта.The data needed to serialize or deserialize an object.
- context
- StreamingContext
Источник и назначение данного сериализованного потока.The source and destination of a given serialized stream.
Комментарии
Эта реализация DataTable конструктора является обязательной для ISerializable .This implementation of the DataTable constructor is required for ISerializable.
См. также раздел
Применяется к
DataTable(String, String)
public:
DataTable(System::String ^ tableName, System::String ^ tableNamespace);
public DataTable (string? tableName, 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)
Параметры
- tableName
- String
Имя, задаваемое таблице.The name to give the table. Если значение параметра tableName
— null
или пустая строка, имя по умолчанию присваивается при добавлении в коллекцию DataTableCollection.If tableName
is null
or an empty string, a default name is given when added to the DataTableCollection.
- tableNamespace
- String
Пространство имен для XML-представления данных, хранящихся в DataTable
.The namespace for the XML representation of the data stored in the DataTable
.