DataTableCollection.Add Metodo

Definizione

Aggiunge un DataTable oggetto all'insieme.

Overload

Nome Descrizione
Add()

Crea un nuovo DataTable oggetto utilizzando un nome predefinito e lo aggiunge alla raccolta.

Add(DataTable)

Aggiunge l'oggetto specificato DataTable all'insieme.

Add(String)

Crea un DataTable oggetto utilizzando il nome specificato e lo aggiunge alla raccolta.

Add(String, String)

Crea un DataTable oggetto utilizzando il nome specificato e lo aggiunge alla raccolta.

Add()

Crea un nuovo DataTable oggetto utilizzando un nome predefinito e lo aggiunge alla raccolta.

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

Valori restituiti

Oggetto appena creato DataTable.

Esempio

Nell'esempio seguente vengono aggiunti tre nuovi DataTable oggetti all'oggetto DataTableCollection utilizzando il Add metodo senza argomenti.

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

Commenti

Poiché non viene specificato alcun nome, l'oggetto DataTable viene creato utilizzando un nome predefinito, rispetto all'ordine di addizione. Il nome predefinito è "Table1".

L'evento CollectionChanged si verifica quando una tabella viene aggiunta correttamente all'insieme.

Vedi anche

Si applica a

Add(DataTable)

Aggiunge l'oggetto specificato DataTable all'insieme.

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

Parametri

table
DataTable

Oggetto DataTable da aggiungere.

Eccezioni

Il valore specificato per la tabella è null.

La tabella appartiene già a questa raccolta o appartiene a un'altra raccolta.

Una tabella nella raccolta ha lo stesso nome. Il confronto non fa distinzione tra maiuscole e minuscole.

Esempio

Nell'esempio seguente viene creato un DataTable oggetto e viene aggiunto all'oggetto DataTableCollection di un oggetto 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);
}

Commenti

L'evento CollectionChanged si verifica quando una tabella viene aggiunta correttamente all'insieme.

Vedi anche

Si applica a

Add(String)

Crea un DataTable oggetto utilizzando il nome specificato e lo aggiunge alla raccolta.

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

Parametri

name
String

Nome da assegnare all'oggetto creato DataTable.

Valori restituiti

Oggetto appena creato DataTable.

Eccezioni

Una tabella nella raccolta ha lo stesso nome. Il confronto non fa distinzione tra maiuscole e minuscole.

Esempio

Nell'esempio seguente viene aggiunto un oggetto DataTable con il nome specificato all'oggetto 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

Commenti

Se viene passata una null o una stringa vuota (""), viene assegnato un nome predefinito all'oggetto appena creato DataTable. Questo nome è basato sull'ordine in cui è stata aggiunta la tabella ("Table1", "Table2" e così via).

L'evento CollectionChanged si verifica se la tabella viene aggiunta correttamente all'insieme.

Vedi anche

Si applica a

Add(String, String)

Crea un DataTable oggetto utilizzando il nome specificato e lo aggiunge alla raccolta.

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

Parametri

name
String

Nome da assegnare all'oggetto creato DataTable.

tableNamespace
String

Spazio dei nomi da assegnare all'oggetto creato DataTable.

Valori restituiti

Oggetto appena creato DataTable.

Eccezioni

Una tabella nella raccolta ha lo stesso nome. Il confronto non fa distinzione tra maiuscole e minuscole.

Esempio

Nell'esempio seguente viene aggiunto un oggetto DataTable con il nome specificato all'oggetto 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

Commenti

Se viene passata una null o una stringa vuota (""), viene assegnato un nome predefinito all'oggetto appena creato DataTable. Questo nome è basato sull'ordine in cui è stata aggiunta la tabella ("Table1", "Table2" e così via).

L'evento CollectionChanged si verifica se la tabella viene aggiunta correttamente all'insieme.

Vedi anche

Si applica a