asp.net.ph

DataView.Table Property

System.Data Namespace   DataView Class


Sets or retrieves the source DataTable.

Syntax


Script DataView.Table [ = strTableName ]

Property Value


strTableName A DataTable that provides the data for this view.

The property is read/write with no default value.

Remarks

The DataTable also has a DefaultView property which returns the default DataView for the table. For example, if you wish to create a custom view on the table, set the RowFilter on the DataView returned by the DefaultView.

Example

The following example gets the DataTable of the current DataView.

private static void DemonstrateDataViewTable ( ) {
   DataTable myTable = new DataTable ( );

   // add columns
   DataColumn 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 = new DataView ( myTable );
   PrintTable ( dv.Table, "DataTable" );
}

private static void PrintTable ( DataTable tbl, string label ) {
   // This function prints values in the table or DataView.
   Response.Write ( label + "<br>" )

   foreach ( DataRow row in tbl.Rows ) {

      foreach ( DataColumn col in tbl.Columns ) {
         Response.Write ( row [ col ] + "<br>" );
      }
    }
}
  C# VB

See Also

DataView Members   DataTable Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph