Dumping DataTable to debug window

Here’s one little method I use to write out debug information when investigating some new (legacy but new to me) system. Usually I remove this method later when I know how 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 :)

Gunnar Peipman

Gunnar Peipman is ASP.NET, Azure and SharePoint fan, Estonian Microsoft user group leader, blogger, conference speaker, teacher, and tech maniac. Since 2008 he is Microsoft MVP specialized on ASP.NET.

    Leave a Reply

    Your email address will not be published. Required fields are marked *