Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Take a C# System.Data.DataTable and dump it to the console for debugging
private static void DumpDataTable(DataTable dt)
{
if((dt == null) || (!SqlHelper.HasRows(dt)))
{
Console.Error.WriteLine("There are no rows");
} else
{
foreach(DataColumn c in dt.Columns)
{
Console.Write($"\"{c.ColumnName}\",");
}
Console.WriteLine("");
foreach(DataRow dr in dt.Rows)
{
for (int i = 0; i < dr.ItemArray.Length; i++)
{
Console.Write($"\"{dr.ItemArray[i]}\",");
}
Console.WriteLine("");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment