次の方法で共有


DataView.Table プロパティ

ソース DataTable を取得または設定します。

Public Property Table As DataTable
[C#]
public DataTable Table {get; set;}
[C++]
public: __property DataTable* get_Table();public: __property void set_Table(DataTable*);
[JScript]
public function get Table() : DataTable;public function set Table(DataTable);

プロパティ値

このビューにデータを提供する DataTable

解説

DataTable には、テーブルの既定の DataView を返す DefaultView プロパティもあります。たとえば、テーブルのカスタム ビューを作成する場合は、 DefaultView によって返された DataView に対して RowFilter を設定します。

現在の値が null の場合は、 Table プロパティだけを設定できます。

使用例

[Visual Basic, C#, C++] 現在の DataViewDataTable を取得する例を次に示します。

 
Private Sub DemonstrateDataViewTable()
    Dim myTable As DataTable
    myTable = new DataTable()
    
    ' add columns
    Dim column As DataColumn
    column = myTable.Columns.Add( "ProductID",    GetType(Integer) )
    column.AutoIncrement = true
    column = myTable.Columns.Add( "ProductName", GetType(String) )

    ' populate DataTable.
    Dim id As Integer
    For id = 1 To 5
        myTable.Rows.Add( _
            new object() { id, string.Format("product{0}", id) } )
    Next id
    
    Dim dv As DataView
    dv = new DataView( myTable )

    PrintTable(dv.Table, "DataTable")
End Sub

Private Sub PrintTable(t As DataTable, label As String)
    ' This function prints values in the table or DataView.
    Console.WriteLine("\n" + label)
    Dim row As DataRow
    Dim c As DataColumn
    For Each row In t.Rows
        For Each c In t.Columns
            Console.Write( "\t{0}", row(c) )
        Next c
    Next row
    Console.WriteLine()
End Sub

[C#] 
private static void DemonstrateDataViewTable()
{
    DataTable myTable;
    myTable = new DataTable();
    
    // add columns
    DataColumn column;
    column = myTable.Columns.Add( "ProductID",    typeof(int)       );
    column.AutoIncrement = true;
    column = myTable.Columns.Add( "ProductName", typeof(string) );

    // populate DataTable.
    for( int id=1; id<=5; id++ )
    {
        myTable.Rows.Add( 
            new object[]{ id, string.Format("product{0}", id) } );
    }
    
    DataView dv;
    dv = new DataView( myTable );

    PrintTable( dv.Table, "DataTable" );
}

private static void PrintTable(DataTable t, string label)
{
    // This function prints values in the table or DataView.
    Console.WriteLine("\n" + label);
    foreach( DataRow row in t.Rows )
    {
        foreach( DataColumn c in t.Columns )
        {
            Console.Write( "\t{0}", row[c] );
        }
        Console.WriteLine();
    }
}

[C++] 
private:
    static void DemonstrateDataViewTable()
    {
        DataTable* myTable;
        myTable = new DataTable();

        // add columns
        DataColumn* column;
        column = myTable->Columns->Add( S"ProductID",    __typeof(int) );
        column->AutoIncrement = true;
        column = myTable->Columns->Add( S"ProductName", __typeof(String) );

        // populate DataTable.
        for( int id=1; id<=5; id++ )
        {
            Object* temp0 [] = {__box(id), String::Format(S"product{0}", __box(id))};
            myTable->Rows->Add( temp0 );
        }

        DataView* dv;
        dv = new DataView( myTable );

        PrintTable( dv->Table, S"DataTable" );
    }

private:
    static void PrintTable(DataTable* t, String* label)
    {
        // This function prints values in the table or DataView.
        Console::WriteLine(S"\n{0}", label);
        System::Collections::IEnumerator* myEnum = t->Rows->GetEnumerator();
        while (myEnum->MoveNext())
        {
            DataRow* row = __try_cast<DataRow*>(myEnum->Current);
            System::Collections::IEnumerator* myEnum1 = t->Columns->GetEnumerator();
            while (myEnum1->MoveNext())
            {
                DataColumn* c = __try_cast<DataColumn*>(myEnum1->Current);
                Console::Write( S"\t{0}", row->Item[c] );
            }
            Console::WriteLine();
        }
    }

[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

参照

DataView クラス | DataView メンバ | System.Data 名前空間 | DataTable