Creates a table with the given name and adds it to the collection.
[Visual Basic] Overloads Overridable 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;
The newly created DataTable.
Exception Type | Condition |
---|---|
DuplicateNameException | A table in the collection has the same name. The comparison is not case-sensitive. |
If either a a null reference (in Visual Basic Nothing) or an empty string ("") is passed in, a default name is given to the newly created DataTable.
The OnCollectionChanged event occurs if the table is succesfully added.
The following example adds a DataTable with the given name to the TablesCollection.
[Visual Basic]
Private Sub GetTableByName() Dim dSet As DataSet Dim dt As DataTable ' Presuming a DataGrid is displaying more than one table, get its DataSet. Set dSet = DataGrid1.DataGridTable.DataTable.DataSet ' Use the Add method to add a new table with a given name. Set dt = dSet.Tables.Add("myNewTable") ' Code to add columns and rows not shown here. MessageBox.Show dt.TableName MessageBox.Show dSet.Tables.Count End Sub
TablesCollection Class | TablesCollection Members | System.Data Namespace | TablesCollection.Add Overload List | DataTable | Remove | Clear