Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Dumping DataTable to debug window

DZone's Guide to

Dumping DataTable to debug window

·
Free Resource
Here’s one little method I use to write out debug information when investigating a new (legacy but new to me) system. Usually I remove this method later when I know how the code works. It’s maybe not the best way to debug things, but it works like charm in many situations.

public void DumpDataTable(DataTable table)

{

    foreach (DataRow row in table.Rows)

    {

        Debug.Print("------------------------------------------");

 

        foreach (DataColumn col in results.Columns)

        {

            Debug.Write(col.ColumnName);

            Debug.Write("=");

            Debug.WriteLine(row[col.ColumnName]);

        }

    }

}

Hope it helps somebody :)
Topics:

Published at DZone with permission of Gunnar Peipman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}