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 🙂


Leave a Reply

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