asp.net.ph

DataTableCollection.Add Method ( String )

System.Data Namespace   DataTableCollection Class


Creates a new DataTable object with the specified name and adds it to the collection.

[ VB ]
Overridable Overloads Public Function Add ( _
   ByVal name As String _
) As DataTable

[ C# ]
public virtual DataTable Add (
   string name
);

[ C++ ]
public: virtual DataTable* Add (
   String* name
);

[ JScript ]
public function Add (
   name : String
) : DataTable;

Parameters

name
The name to give the created DataTable.

Return Value

The newly created DataTable.

Exceptions


Exception Type Condition
DuplicateNameException Occurs when a table in the collection has the same name. The comparison is not case-sensitive.

Remarks

If either a null reference or an empty string ( "" ) is passed in, a default name is given to the newly created DataTable. This name is based on the order in which the table was added ( Table1, Table2, etc. ).

The CollectionChanged event occurs when a table is successfully added to the collection.

Example

The following example adds a DataTable with the given name to the DataTableCollection.

private void AddTable ( DataSet ds ) {
   DataTableCollection myTables = ds.Tables;
   // add a new table with a given name.
   DataTable myTable = myTables.Add ( "myNewTable" );
   myTable.Columns.Add ( "ID", typeof ( int ) );
   myTable.Columns.Add ( "Name", typeof ( string ) );
   Response.Write ( myTables.Count.ToString ( ) );
}
  C# VB

See Also

DataTableCollection Members   DataTableCollection.Add Overload List   Clear   DataTable   Remove 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