views:

51

answers:

1

When I'm debugging a datatable, say in the watch window, I'll often choose the Rows property, and then a particular index-- 0 or 1, often times.

When I do that, I see an ItemArray list with numeric indexing, representing the columns for the row. But the columns have names, and I'd like to see them. So instead of

myTable.Rows[0][6]

...where I'm guessing/pretty-but-not-quite sure the LastName column is in that location, I'd prefer to see the ItemArray list with the column names between the [] brackets, so I know for sure. Is there a property here I'm not seeing or is there a way to do it?

+1  A: 

Hi,

myTable.Rows[0]["columnName"] isn't work for you?

If you want to get a list of "columnName-value" you can use some kind of debug-helper:

class DebugHelper {
    public static Dictionary<string, object> GetValues(DataTable table, int rowId) {
        Dictionary<string, object> result = new Dictionary<string,object>();
        foreach(DataColumn column in table.Columns)
            result.Add(column.Caption, table.Rows[rowId][column]);
        return result;
    }
}

In watch, use DebugHelper.GetValues(table, 0)

Beresta
Thanks for the code snippet. As for your first question, I certainly can do myTable.Rows[0]["ColumnName"], but sometimes if I'm debugging someone else's code I don't know what the ColumnNames are at the debugging point. It would be nice to be able to drill down to see them, instead of column [0], [1] etc, which is all I can see by default in the watch window.
larryq