DataTableCollection.Add Metodo

Definizione

Aggiunge un oggetto DataTable alla raccolta.

Overload

Add()

Crea un nuovo oggetto DataTable, utilizzando un nome predefinito, e lo aggiunge all'insieme.

Add(DataTable)

Aggiunge l'oggetto DataTable specificato alla raccolta.

Add(String)

Crea un oggetto DataTable utilizzando il nome specificato e lo aggiunge all'insieme.

Add(String, String)

Crea un oggetto DataTable utilizzando il nome specificato e lo aggiunge all'insieme.

Add()

Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs

Crea un nuovo oggetto DataTable, utilizzando un nome predefinito, e lo aggiunge all'insieme.

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

Restituisce

Oggetto DataTable appena creato.

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, viene DataTable 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)

Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs

Aggiunge l'oggetto DataTable specificato alla raccolta.

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)

Parametri

table
DataTable

L'oggetto DataTable da aggiungere.

Eccezioni

Il valore specificato per la tabella è null.

La tabella appartiene già a questo insieme oppure appartiene a un altro insieme.

Nell'insieme è presente una tabella con lo stesso nome. Per il confronto non viene effettuata alcuna distinzione tra maiuscole e minuscole.

Esempio

Nell'esempio seguente viene creato un oggetto DataTable 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)

Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs

Crea un oggetto DataTable utilizzando il nome specificato e lo aggiunge all'insieme.

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

Parametri

name
String

Nome da assegnare all'oggetto DataTable creato.

Restituisce

Oggetto DataTable appena creato.

Eccezioni

Nell'insieme è presente una tabella con lo stesso nome. Per il confronto non viene effettuata alcuna distinzione tra maiuscole e minuscole.

Esempio

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

Commenti

null Se una o una stringa vuota ("") viene passata, viene assegnato un nome predefinito all'oggetto appena creatoDataTable. Questo nome si basa 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)

Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs

Crea un oggetto DataTable utilizzando il nome specificato e lo aggiunge all'insieme.

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

Parametri

name
String

Nome da assegnare all'oggetto DataTable creato.

tableNamespace
String

Spazio dei nomi da assegnare all'oggetto DataTable creato.

Restituisce

Oggetto DataTable appena creato.

Eccezioni

Nell'insieme è presente una tabella con lo stesso nome. Per il confronto non viene effettuata alcuna distinzione tra maiuscole e minuscole.

Esempio

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

Commenti

null Se una o una stringa vuota ("") viene passata, viene assegnato un nome predefinito all'oggetto appena creatoDataTable. Questo nome si basa 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