DataTableCollection.RemoveAt メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataTableCollection.RemoveAt メソッドの意味・解説 

DataTableCollection.RemoveAt メソッド

指定したインデックス位置にある DataTable オブジェクトコレクションから削除します

名前空間: System.Data
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Sub RemoveAt ( _
    index As Integer _
)
Dim instance As DataTableCollection
Dim index As Integer

instance.RemoveAt(index)
public void RemoveAt (
    int index
)
public:
void RemoveAt (
    int index
)
public void RemoveAt (
    int index
)

パラメータ

index

削除する DataTableインデックス

例外例外
例外種類条件

ArgumentException

このコレクションには指定したインデックス位置テーブルがありません。

解説解説
使用例使用例

Contains メソッドと CanRemove メソッド使用してインデックス 10テーブル存在するかどうか確認する例を次に示しますテーブル存在する場合は、テーブル削除するために RemoveAt メソッド呼び出されます。

Public Sub DataTableCollectionRemoveAt()
    ' Create a DataSet with two tables and then
    ' remove the tables from the collection using RemoveAt.
    Dim dataSet As DataSet = New
 DataSet()

    ' Create Customer table.
    Dim customerTable As DataTable = New
 DataTable("Customers")
    customerTable.Columns.Add("customerId", _
        GetType(Integer)).AutoIncrement = True
    customerTable.Columns.Add("name", GetType(String))
    customerTable.PrimaryKey = New DataColumn() _
        {customerTable.Columns("customerId")}

    ' Create Orders table.
    Dim ordersTable As DataTable = New
 DataTable("Orders")
    ordersTable.Columns.Add("orderId", _
        GetType(Integer)).AutoIncrement = True
    ordersTable.Columns.Add("customerId", GetType(Integer))
    ordersTable.Columns.Add("amount", GetType(Double))
    ordersTable.PrimaryKey = New DataColumn() _
        {ordersTable.Columns("orderId")}

    dataSet.Tables.AddRange(New DataTable() _
        {customerTable, ordersTable})

    ' Remove all tables.
    ' First check to see if the table can be removed,
    ' then remove it.
    '
    ' You cannot use a foreach when removing items
    ' from a collection.
    Do While (dataSet.Tables.Count > 0)
        Dim table As DataTable = dataSet.Tables(0)
        If (dataSet.Tables.CanRemove(table)) Then
            dataSet.Tables.RemoveAt(0)
        End If
        Console.WriteLine("dataSet has {0} tables",
 _
            dataSet.Tables.Count)
    Loop
End Sub
public static void DataTableCollectionRemoveAt()
{
    // Create a DataSet with two tables and then
    // remove the tables from the collection using RemoveAt.
    DataSet dataSet = new DataSet();

    // Create Customer table.
    DataTable customerTable = new DataTable("Customers");
    customerTable.Columns.Add("customerId",
        typeof(int)).AutoIncrement = true;
    customerTable.Columns.Add("name", typeof(string));
    customerTable.PrimaryKey = new DataColumn[] { customerTable.Columns["customerId"]
 };

    // Create Orders table.
    DataTable ordersTable = new DataTable("Orders");
    ordersTable.Columns.Add("orderId",
        typeof(int)).AutoIncrement = true;
    ordersTable.Columns.Add("customerId", typeof(int));
    ordersTable.Columns.Add("amount", typeof(double));
    ordersTable.PrimaryKey = new DataColumn[] { ordersTable.Columns["orderId"]
 };

    dataSet.Tables.AddRange(new DataTable[] { customerTable, ordersTable
 });

    // Remove all tables.
    // First check to see if the table can be removed,
    // then remove it.
    //
    // You cannot use a foreach when removing items
    // from a collection.
    while (dataSet.Tables.Count > 0)
    {
        DataTable table = dataSet.Tables[0];
        if (dataSet.Tables.CanRemove(table))
            dataSet.Tables.RemoveAt(0);
        Console.WriteLine("dataSet has {0} tables",
            dataSet.Tables.Count);
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataTableCollection クラス
DataTableCollection メンバ
System.Data 名前空間
IndexOf
Contains


このページでは「.NET Framework クラス ライブラリ リファレンス」からDataTableCollection.RemoveAt メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDataTableCollection.RemoveAt メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDataTableCollection.RemoveAt メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

DataTableCollection.RemoveAt メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataTableCollection.RemoveAt メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS