Skip to content

Instantly share code, notes, and snippets.

@BlitzkriegSoftware
Created April 13, 2020 23:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BlitzkriegSoftware/59e28d8c1f9d9809b53812949f2a4e02 to your computer and use it in GitHub Desktop.
Save BlitzkriegSoftware/59e28d8c1f9d9809b53812949f2a4e02 to your computer and use it in GitHub Desktop.
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