System.Data Namespace DataTableCollection Class
Adds a DataTable to the collection.
1. Creates a new DataTable object with a default name and adds it to the collection.
2. Adds the specified DataTable to the collection.
3. Creates a DataTable object with the specified name and adds it to the collection.
The following example adds a DataTable with the given name to the DataTableCollection.
NOTE: This example uses one of the overloaded versions of Add. For other examples that may be available, see the individual overload topics.
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 ( ) );
}
Private Sub AddTable ( ByVal ds As DataSet )
Dim myTables As DataTableCollection = ds.Tables
' add a new table with a given name.
Dim myTable As DataTable = myTables.Add ( "myNewTable" )
myTable.Columns.Add ( "ID", Type.GetType ( "System.Int32" ) )
myTable.Columns.Add ( "Name", Type.GetType ( "System.String" ) )
Response.Write ( myTables.Count.ToString ( ) )
End Sub |
|
C# |
VB |
DataTableCollection Members