asp.net.ph

DataTable Constructor ( String )

System.Data Namespace   DataTable Class


Intitalizes a new instance of the DataTable class with the specified table name.

[ VB ]
Public Sub New ( _
   ByVal tableName As String _
)

[ C# ]
public DataTable (
   String tableName
);

[ C++ ]
public: DataTable (
   String* tableName
);

[ JScript ]
public function DataTable (
   tableName : String
);

Parameters

tableName
The name to give the table. If a null reference or an empty string, a default name will be given when added to the DataTableCollection.

Example

The following example initializes a DataTable with a given table name.

Private void DataTableDemo ( ) {
   // create new DataTable.
   DataTable myDataTable = new DataTable ( "myDataTable" );

   // declare DataColumn and DataRow variables.
   DataColumn myDataColumn;
   DataRow myDataRow;

   // create new DataColumn, set DataType, ColumnName and add to DataTable.
   myDataColumn = new DataColumn ( );
   myDataColumn.DataType = System.Type.GetType ( "System.Int32" );
   myDataColumn.ColumnName = "id";
   myDataTable.Columns.Add ( myDataColumn );

   // create new DataRow objects and add to DataTable.

   for ( int i = 0; i < 10; i++ ) {
      myDataRow = myDataTable.NewRow ( );
      myDataRow [ "id" ] = i;
      myDataRow [ "item" ] = "item " + i;
      myDataTable.Rows.Add ( myDataRow );
   }
}
  C# VB

See Also

DataTable Members   DataTable Constructor Overload List   DataColumn   DataRow   DataView 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