System.Data Namespace DataTableCollection Class
Adds the specified DataTable to the collection.
[ VB ]
Overridable Overloads Public Sub Add ( _
ByVal table As DataTable _
)
[ C# ]
public virtual void Add (
DataTable table
);
[ C++ ]
public: virtual void Add (
DataTable* table
);
[ JScript ]
public function Add (
table : DataTable
);
- table
- The DataTable object to add.
Exception Type |
Condition |
ArgumentNullException |
Occurs when the value specified for the table is a null reference. |
ArgumentException |
Occurs when the table already belongs to this collection, or belongs to another collection. |
DuplicateNameException |
Occurs when a table in the collection has the same name. The comparison is not case-sensitive. |
The CollectionChanged event occurs when a table is succefully added to the collection.
The following example initializes a DataTable and adds it to the DataTableCollection of a given DataSet.
private void AddTable ( DataSet ds ) {
// create a new DataTable.
DataTable myTable = new DataTable ( );
myTable.Columns.Add ( "ID", typeof ( int ) );
myTable.Columns.Add ( "Name", typeof ( string ) );
// add the table to the DataTableCollection.
ds.Tables.Add ( myTable );
}
Private Sub AddTable ( ByVal ds As DataSet )
' create a new DataTable.
Dim myTable As New DataTable
myTable.Columns.Add ( "ID", Type.GetType ( "System.Int32" ) )
myTable.Columns.Add ( "Name", Type.GetType ( "System.String" ) )
' add the table to the DataTableCollection.
ds.Tables.Add ( myTable )
End Sub |
|
C# |
VB |
DataTableCollection Members DataTableCollection.Add Overload List Clear DataTable Remove