DataView.Table 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定來源 DataTable。
public:
property System::Data::DataTable ^ Table { System::Data::DataTable ^ get(); void set(System::Data::DataTable ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Data.DataTableTypeConverter))]
public System.Data.DataTable? Table { get; set; }
public System.Data.DataTable Table { get; set; }
[System.ComponentModel.TypeConverter(typeof(System.Data.DataTableTypeConverter))]
[System.Data.DataSysDescription("DataViewTableDescr")]
public System.Data.DataTable Table { get; set; }
[System.ComponentModel.TypeConverter(typeof(System.Data.DataTableTypeConverter))]
public System.Data.DataTable Table { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Data.DataTableTypeConverter))>]
member this.Table : System.Data.DataTable with get, set
member this.Table : System.Data.DataTable with get, set
[<System.ComponentModel.TypeConverter(typeof(System.Data.DataTableTypeConverter))>]
[<System.Data.DataSysDescription("DataViewTableDescr")>]
member this.Table : System.Data.DataTable with get, set
Public Property Table As DataTable
屬性值
為這個檢視提供資料的 DataTable。
- 屬性
範例
下列範例會取得 DataTable 目前 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",
typeof(string));
// populate DataTable.
for(int id=1; id<=5; id++)
{
table.Rows.Add(
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]);
}
Console.WriteLine();
}
}
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
Console.WriteLine()
End Sub
備註
DataTable也有 DefaultView 屬性,這個屬性會傳回數據表的預設值DataView。 例如,如果您要在資料表上建立自訂檢視,請在 所傳回的 DefaultView上DataView設定 RowFilter 。
只有當目前的值為 Null 時,您才能設定 Table 屬性。