Export (0) Print
Expand All

DataTable.TableName Property

Gets or sets the name of the DataTable.

[Visual Basic]
Public Property TableName As String
public string TableName {get; set;}
public: __property String* get_TableName();
public: __property void set_TableName(String*);
public function get TableName() : String;
public function set TableName(String);

Property Value

The name of the DataTable.


Exception Type Condition
ArgumentException A null reference (Nothing in Visual Basic) or empty string ("") is passed in and this table belongs to a collection.
DuplicateNameException The table belongs to a collection that already has a table with the same name, with the name being case-sensitive).


The TableName is used to return this table from the parent DataSet object's DataTableCollection (returned by the Tables property).


[Visual Basic, C#, C++] The following example prints the TableName for each table in a collection of DataTable objects.

[Visual Basic] 
Private Sub GetTableNames(myDataSet As DataSet)
    ' Print each table's TableName.
    Dim t As DataTable
    For Each t In myDataSet.Tables
    Next t
End Sub

private void GetTableNames(DataSet myDataSet){
   // Print each table's TableName.
   foreach(DataTable t in myDataSet.Tables){

 void GetTableNames(DataSet* myDataSet){
    // Print each table's TableName.
    System::Collections::IEnumerator* myEnum = myDataSet->Tables->GetEnumerator();
    while (myEnum->MoveNext())
       DataTable* t = __try_cast<DataTable*>(myEnum->Current);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataTable Class | DataTable Members | System.Data Namespace | DataSet | Tables

© 2014 Microsoft