DataTableCollection.Add Método

Definición

Agrega un objeto DataTable a la colección.

Sobrecargas

Add()

Crea un nuevo objeto DataTable utilizando un nombre predeterminado y lo agrega a la colección.

Add(DataTable)

Agrega el DataTable especificado a la colección.

Add(String)

Crea un objeto DataTable utilizando el nombre especificado y lo agrega a la colección.

Add(String, String)

Crea un objeto DataTable utilizando el nombre especificado y lo agrega a la colección.

Add()

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs

Crea un nuevo objeto DataTable utilizando un nombre predeterminado y lo agrega a la colección.

public:
 System::Data::DataTable ^ Add();
public:
 virtual System::Data::DataTable ^ Add();
public System.Data.DataTable Add ();
public virtual System.Data.DataTable Add ();
member this.Add : unit -> System.Data.DataTable
abstract member Add : unit -> System.Data.DataTable
override this.Add : unit -> System.Data.DataTable
Public Function Add () As DataTable
Public Overridable Function Add () As DataTable

Devoluciones

Colección DataTable creada recientemente.

Ejemplos

En el ejemplo siguiente se agregan tres nuevos DataTable objetos al DataTableCollection uso del Add método sin argumentos.

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

Comentarios

Dado que no se especifica ningún nombre, DataTable se crea mediante un nombre predeterminado, en relación con su orden de suma. El nombre predeterminado es "Table1".

El CollectionChanged evento se produce cuando una tabla se agrega correctamente a la colección.

Consulte también

Se aplica a

Add(DataTable)

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs

Agrega el DataTable especificado a la colección.

public:
 void Add(System::Data::DataTable ^ table);
public:
 virtual void Add(System::Data::DataTable ^ table);
public void Add (System.Data.DataTable table);
public virtual void Add (System.Data.DataTable table);
member this.Add : System.Data.DataTable -> unit
abstract member Add : System.Data.DataTable -> unit
override this.Add : System.Data.DataTable -> unit
Public Sub Add (table As DataTable)
Public Overridable Sub Add (table As DataTable)

Parámetros

table
DataTable

Objeto DataTable que se agrega.

Excepciones

El valor especificado para la tabla es null.

La tabla ya pertenece a esta colección o pertenece a otra colección.

Una tabla de la colección tiene el mismo nombre. La comparación no distingue entre mayúsculas y minúsculas.

Ejemplos

En el ejemplo siguiente se crea un DataTable objeto y se agrega a de DataTableCollection .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);
}

Comentarios

El CollectionChanged evento se produce cuando una tabla se agrega correctamente a la colección.

Consulte también

Se aplica a

Add(String)

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs

Crea un objeto DataTable utilizando el nombre especificado y lo agrega a la colección.

public:
 System::Data::DataTable ^ Add(System::String ^ name);
public:
 virtual System::Data::DataTable ^ Add(System::String ^ name);
public System.Data.DataTable Add (string? name);
public System.Data.DataTable Add (string name);
public virtual System.Data.DataTable Add (string name);
member this.Add : string -> System.Data.DataTable
abstract member Add : string -> System.Data.DataTable
override this.Add : string -> System.Data.DataTable
Public Function Add (name As String) As DataTable
Public Overridable Function Add (name As String) As DataTable

Parámetros

name
String

Nombre que se va a asignar al DataTable creado.

Devoluciones

Colección DataTable creada recientemente.

Excepciones

Una tabla de la colección tiene el mismo nombre. La comparación no distingue entre mayúsculas y minúsculas.

Ejemplos

En el ejemplo siguiente se agrega un DataTable con el nombre especificado a 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

Comentarios

Si se pasa una null cadena vacía (""), se asigna un nombre predeterminado al objeto recién creado DataTable. Este nombre se basa en el orden en que se agregó la tabla ("Table1", "Table2", etc.).

El CollectionChanged evento se produce si la tabla se agrega correctamente a la colección.

Consulte también

Se aplica a

Add(String, String)

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs

Crea un objeto DataTable utilizando el nombre especificado y lo agrega a la colección.

public:
 System::Data::DataTable ^ Add(System::String ^ name, System::String ^ tableNamespace);
public System.Data.DataTable Add (string? name, 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

Parámetros

name
String

Nombre que se va a asignar al DataTable creado.

tableNamespace
String

Espacio de nombres que se va a asignar al objeto DataTable creado.

Devoluciones

Colección DataTable creada recientemente.

Excepciones

Una tabla de la colección tiene el mismo nombre. La comparación no distingue entre mayúsculas y minúsculas.

Ejemplos

En el ejemplo siguiente se agrega un DataTable con el nombre especificado a 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

Comentarios

Si se pasa una null cadena vacía (""), se asigna un nombre predeterminado al objeto recién creado DataTable. Este nombre se basa en el orden en que se agregó la tabla ("Table1", "Table2", etc.).

El CollectionChanged evento se produce si la tabla se agrega correctamente a la colección.

Consulte también

Se aplica a