Export (0) Print
Expand All

DataTable.TableName Property

Gets or sets the name of the DataTable.

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

Property Value

The name of the DataTable.

Exceptions

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).

Remarks

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

Example

[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
        Console.WriteLine(t.TableName)
    Next t
End Sub

[C#] 
private void GetTableNames(DataSet myDataSet){
   // Print each table's TableName.
   foreach(DataTable t in myDataSet.Tables){
      Console.WriteLine(t.TableName);
   }
}

[C++] 
private:
 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);
       Console::WriteLine(t->TableName);
    }
 }

[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.

Requirements

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

Show:
© 2014 Microsoft