DataTableCollection.Add Метод
Определение
Перегрузки
Add() |
Создает новый объект DataTable, используя имя по умолчанию, и добавляет его в коллекцию.Creates a new DataTable object by using a default name and adds it to the collection. |
Add(DataTable) |
Добавляет указанный параметр |
Add(String) |
Создает объект DataTable, используя заданное имя, и добавляет его в коллекцию.Creates a DataTable object by using the specified name and adds it to the collection. |
Add(String, String) |
Создает объект DataTable, используя заданное имя, и добавляет его в коллекцию.Creates a DataTable object by using the specified name and adds it to the collection. |
Add()
Создает новый объект DataTable, используя имя по умолчанию, и добавляет его в коллекцию.Creates a new DataTable object by using a default name and adds it to the collection.
public:
virtual System::Data::DataTable ^ Add();
public virtual System.Data.DataTable Add ();
abstract member Add : unit -> System.Data.DataTable
override this.Add : unit -> System.Data.DataTable
Public Overridable Function Add () As DataTable
Возвраты
Примеры
В следующем примере в DataTable Add метод добавляются три новых DataTableCollection объекта с использованием метода без аргументов.The following example adds three new DataTable objects to the DataTableCollection using the Add method without arguments.
private void AddTables()
{
// Presuming a DataGrid is displaying more than one table,
// get its DataSet.
DataSet thisDataSet = (DataSet)DataGrid1.DataSource;
for (int i = 0; i < 3; i++)
thisDataSet.Tables.Add();
Console.WriteLine(thisDataSet.Tables.Count.ToString()
+ " tables");
foreach (DataTable table in thisDataSet.Tables)
Console.WriteLine(table.TableName);
}
Private Sub AddTables()
Dim table As DataTable
' Presuming a DataGrid is displaying more than one table, get its DataSet.
Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)
Dim i As Integer
For i = 0 to 2
thisDataSet.Tables.Add()
Next i
Console.WriteLine(thisDataSet.Tables.Count.ToString() & " tables")
For Each table In thisDataSet.Tables
Console.WriteLine(table.TableName)
Next
End Sub
Комментарии
Поскольку имя не указано, DataTable
создается с использованием имени по умолчанию относительно его порядка добавления.Because no name is specified, the DataTable
is created by using a default name, relative to its order of addition. Имя по умолчанию — Table1.The default name is "Table1."
Это CollectionChanged событие возникает при успешном добавлении таблицы в коллекцию.The CollectionChanged event occurs when a table is successfully added to the collection.
Дополнительно
Add(DataTable)
Добавляет указанный параметр DataTable
в коллекцию.Adds the specified DataTable
to the collection.
public:
virtual void Add(System::Data::DataTable ^ table);
public virtual void Add (System.Data.DataTable table);
abstract member Add : System.Data.DataTable -> unit
override this.Add : System.Data.DataTable -> unit
Public Overridable Sub Add (table As DataTable)
Параметры
- table
- DataTable
Добавляемый объект DataTable
.The DataTable
object to add.
Исключения
Значением, заданным для таблицы, является null
.The value specified for the table is null
.
Таблица уже принадлежит данной или другой коллекции.The table already belongs to this collection, or belongs to another collection.
Таблица в коллекции имеет такое же имя.A table in the collection has the same name. Сравнение выполняется без учета регистра.The comparison is not case sensitive.
Примеры
В следующем примере создается DataTable и добавляется DataTableCollection в коллекцию DataSet.The following example creates a DataTable and adds it to the DataTableCollection of a DataSet.
private void AddDataTable()
{
// Get the DataTableCollection of a DataGrid
// control's DataSet.
DataTableCollection tables =
((DataSet)DataGrid1.DataSource).Tables;
// Create a new DataTable.
DataTable table = new DataTable();
// Code to add columns and rows not shown here.
// Add the table to the DataTableCollection.
tables.Add(table);
}
Комментарии
Это CollectionChanged событие возникает при успешном добавлении таблицы в коллекцию.The CollectionChanged event occurs when a table is successfully added to the collection.
Дополнительно
Add(String)
Создает объект DataTable, используя заданное имя, и добавляет его в коллекцию.Creates a DataTable object by using the specified name and adds it to the collection.
public:
virtual System::Data::DataTable ^ Add(System::String ^ name);
public virtual System.Data.DataTable Add (string name);
abstract member Add : string -> System.Data.DataTable
override this.Add : string -> System.Data.DataTable
Public Overridable Function Add (name As String) As DataTable
Параметры
Возвраты
Исключения
Таблица в коллекции имеет такое же имя.A table in the collection has the same name. (Сравнение выполняется без учета регистра).(The comparison is not case sensitive.)
Примеры
В следующем примере добавляется DataTable с заданным именем DataTableCollectionв.The following example adds a DataTable with the given name to the DataTableCollection.
private void AddTable()
{
// Presuming a DataGrid is displaying more than one table,
// get its DataSet.
DataSet thisDataSet = (DataSet)DataGrid1.DataSource;
// Use the Add method to add a new table with a given name.
DataTable table = thisDataSet.Tables.Add("NewTable");
// Code to add columns and rows not shown here.
Console.WriteLine(table.TableName);
Console.WriteLine(thisDataSet.Tables.Count.ToString());
}
Private Sub AddTable()
' Presuming a DataGrid is displaying more than one table,
' get its DataSet.
Dim thisDataSet As DataSet = _
CType(DataGrid1.DataSource, DataSet)
' Use the Add method to add a new table with a given name.
Dim table As DataTable = thisDataSet.Tables.Add("NewTable")
' Code to add columns and rows not shown here.
Console.WriteLine(table.TableName)
Console.WriteLine(thisDataSet.Tables.Count.ToString())
End Sub
Комментарии
Если передается либо null
пустая строка (""), имя по умолчанию присваивается только что созданному DataTable
.If either null
or an empty string ("") is passed in, a default name is given to the newly created DataTable
. Это имя основано на порядке добавления таблицы ("table1", "Table2" и т. д.).This name is based on the order in which the table was added ("Table1", "Table2", and so on).
Это CollectionChanged событие возникает, если таблица успешно добавлена в коллекцию.The CollectionChanged event occurs if the table is successfully added to the collection.
Дополнительно
Add(String, String)
Создает объект DataTable, используя заданное имя, и добавляет его в коллекцию.Creates a DataTable object by using the specified name and adds it to the collection.
public:
System::Data::DataTable ^ Add(System::String ^ name, System::String ^ tableNamespace);
public System.Data.DataTable Add (string name, string tableNamespace);
member this.Add : string * string -> System.Data.DataTable
Public Function Add (name As String, tableNamespace As String) As DataTable
Параметры
- tableNamespace
- String
Пространство имен, задаваемое созданному объекту DataTable.The namespace to give the created DataTable.
Возвраты
Исключения
Таблица в коллекции имеет такое же имя.A table in the collection has the same name. (Сравнение выполняется без учета регистра).(The comparison is not case sensitive.)
Примеры
В следующем примере добавляется DataTable с заданным именем DataTableCollectionв.The following example adds a DataTable with the given name to the DataTableCollection.
private void AddTable()
{
// Presuming a DataGrid is displaying more than one table,
// get its DataSet.
DataSet thisDataSet = (DataSet)DataGrid1.DataSource;
// Use the Add method to add a new table with a given name.
DataTable table = thisDataSet.Tables.Add("NewTable");
// Code to add columns and rows not shown here.
Console.WriteLine(table.TableName);
Console.WriteLine(thisDataSet.Tables.Count.ToString());
}
Private Sub AddTable()
' Presuming a DataGrid is displaying more than one table,
' get its DataSet.
Dim thisDataSet As DataSet = _
CType(DataGrid1.DataSource, DataSet)
' Use the Add method to add a new table with a given name.
Dim table As DataTable = thisDataSet.Tables.Add("NewTable")
' Code to add columns and rows not shown here.
Console.WriteLine(table.TableName)
Console.WriteLine(thisDataSet.Tables.Count.ToString())
End Sub
Комментарии
Если передается либо null
пустая строка (""), имя по умолчанию присваивается только что созданному DataTable
.If either null
or an empty string ("") is passed in, a default name is given to the newly created DataTable
. Это имя основано на порядке добавления таблицы ("table1", "Table2" и т. д.).This name is based on the order in which the table was added ("Table1", "Table2", and so on).
Это CollectionChanged событие возникает, если таблица успешно добавлена в коллекцию.The CollectionChanged event occurs if the table is successfully added to the collection.