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;
- name
- The name to give the created DataTable.
The newly created DataTable.
Exception Type |
Condition |
DuplicateNameException |
Occurs when a table in the collection has the same name. The comparison is not case-sensitive. |
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.
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 ( ) );
}
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 DataTableCollection.Add Overload List Clear DataTable Remove