次の方法で共有


DataTableCollection.Add メソッド (DataTable)

指定した DataTable をコレクションに追加します。

Overloads Public Overridable Sub Add( _
   ByVal table As DataTable _)
[C#]
public virtual void Add(DataTabletable);
[C++]
public: virtual void Add(DataTable* table);
[JScript]
public function Add(
   table : DataTable);

パラメータ

  • table
    追加する DataTable オブジェクト。

例外

例外の種類 条件
ArgumentNullException このテーブルに指定した値が null 参照 (Visual Basic では Nothing) です。
ArgumentException このテーブルは既にこのコレクションに属しているか、他のコレクションに属しています。
DuplicateNameException コレクション内に同じ名前のテーブルがあります。比較では大文字と小文字が区別されません。

解説

OnCollectionChanged イベントは、テーブルがコレクションに正常に追加されたときに発生します。

使用例

[Visual Basic, C#, C++] DataTable を作成し、このオブジェクトを DataSetDataTableCollection に追加する例を次に示します。

 
Private Sub AddDataTable()
   Dim tablesCol As DataTableCollection
   ' Get the DataTableCollection of a DataGrid control's DataSet.
   tablesCol = CType(DataGrid1.DataSource, DataSet).Tables
   ' Create a new DataTable.
   Dim myTable As DataTable = New DataTable
   ' Code to add columns and rows not shown here.
   
   ' Add the table to the DataTableCollection.
   tablesCol.Add(myTable)
End Sub

[C#] 
private void AddDataTable()
{
   // Get the DataTableCollection of a DataGrid control's DataSet.
   DataTableCollection tablesCol = ((DataSet)DataGrid1.DataSource).Tables;
   // Create a new DataTable.
   DataTable myTable = new DataTable();
   // Code to add columns and rows not shown here.
   
   // Add the table to the DataTableCollection.
   tablesCol.Add(myTable);
}

[C++] 
private:
 void AddDataTable()
 {
    // Get the DataTableCollection of a DataGrid control's DataSet.
    DataTableCollection* tablesCol = (dynamic_cast<DataSet*>(DataGrid1->DataSource))->Tables;
    // Create a new DataTable.
    DataTable* myTable = new DataTable();
    // Code to add columns and rows not shown here.
    
    // Add the table to the DataTableCollection.
    tablesCol->Add(myTable);
 }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

DataTableCollection クラス | DataTableCollection メンバ | System.Data 名前空間 | DataTableCollection.Add オーバーロードの一覧 | DataTable | Remove | Clear