Export (0) Print
Expand All

DataColumn.ToString Method

Gets the Expression of the column, if one exists.

[Visual Basic]
Overrides Public Function ToString() As String
[C#]
public override string ToString();
[C++]
public: String* ToString();
[JScript]
public override function ToString() : String;

Return Value

The Expression value, if the property is set; otherwise, the ColumnName property.

Example

[Visual Basic, C#, C++] The following example uses the ToString property to return the default string of each member of a collection of DataColumn objects.

[Visual Basic] 
Private Sub PrintColumns(myTable As DataTable)
    ' Print the default string of each column in a collection.
    Dim myColumn As DataColumn
    For Each myColumn In myTable.Columns
       Console.WriteLine(myColumn.ToString())
    Next
 End Sub

[C#] 
private void PrintColumns(DataTable myTable){
    // Print the default string of each column in a collection.
    foreach(DataColumn myColumn in myTable.Columns){
       Console.WriteLine(myColumn.ToString());
    }
 }

[C++] 
private:
void PrintColumns(DataTable* myTable){
    // Print the default string of each column in a collection.
    System::Collections::IEnumerator* myEnum = myTable->Columns->GetEnumerator();
    while (myEnum->MoveNext())
    {
        DataColumn* myColumn = __try_cast<DataColumn*>(myEnum->Current);
        Console::WriteLine(myColumn->ToString());
    }
}

[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

DataColumn Class | DataColumn Members | System.Data Namespace | Expression | ColumnName

Show:
© 2014 Microsoft