DataView.Table 屬性


取得或設定來源 DataTableGets or sets the source DataTable.

 property System::Data::DataTable ^ Table { System::Data::DataTable ^ get(); void set(System::Data::DataTable ^ value); };
public System.Data.DataTable Table { get; set; }
member this.Table : System.Data.DataTable with get, set
Public Property Table As DataTable


為這個檢視提供資料的 DataTableA DataTable that provides the data for this view.



下列範例會取得DataTable目前DataView的。The following example gets the DataTable of the current DataView.

private static void DemonstrateDataViewTable()
    DataTable table = new DataTable();

    // add columns
    DataColumn column = table.Columns.Add("ProductID",
        typeof(int)	);
    column.AutoIncrement = true;
    column = table.Columns.Add("ProductName", 

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

    DataView view = new DataView(table);

    PrintTable(view.Table, "DataTable");

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

    ' add columns
    Dim column As DataColumn = table.Columns.Add("ProductID", GetType(Integer))
    column.AutoIncrement = True
    column = table.Columns.Add("ProductName", GetType(String))

    ' populate DataTable.
    Dim id As Integer
    For id = 1 To 5
        table.Rows.Add(New Object() {id, String.Format("product{0}", id)})
    Next id

    Dim view As New DataView(table)

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

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


也有屬性, 它會傳回資料表的DataView預設值。 DefaultView DataTableThe DataTable also has a DefaultView property which returns the default DataView for the table. 例如, 如果您想要在資料表上建立自訂視圖, 請在所RowFilter傳回DefaultViewDataView上設定。For example, if you want to create a custom view on the table, set the RowFilter on the DataView returned by the DefaultView.

只有當目前的值Table為 null 時, 才能設定屬性。You can only set the Table property if the current value is null.