Search code examples
visual-studio-2008datatablewatchdatacolumn

Seeing named datacolumns in Visual Studio debugger?


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?


Solution

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