
Introduction
Debugging when working with databases can be a very ugly job. Especially when most of the data tables are created in runtime. Of course, you can set a breakpoint when your dataset or data table is filled, but you need to scroll a lot to find out which data is in the table, which column names are used, etc. The solution for this problem is described here. It helps me a lot, so hopefully it's helpful for you. To work with this tool, you need to add a little code in your program. Declare a global DataSet to your program like:
public DataSet ds = new DataSet();
At the point where you normally add a breakpoint for watching your data tables, just add:
ds.Tables.Add(myDatatable);
You can do this on many points in your program if you like. In the end, you want to see what's inside the tables, so add these lines:
ds.WriteXml(Server.MapPath("myDataset.xml"));
ds.WriteXml(@"C:\myDataset.xml");
As you know, you need to have write permission to that folder.
Set up the environment
That's the first part; with a few lines of extra code, you've created an XML file with your complete dataset. Now here's how the tool helps. Just place the executable file in any location that you like (for example: 'C:\MyTools\Showdataset\'). Add a shortcut to 'Showdataset.exe' from your SendTo folder. To find out where this folder is located, check your Registry at this location: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders. Double-click on the SendTo value to copy your path. Close regedit and paste this path in the address bar of your Explorer. Open another Explorer and browse to the folder where 'Showdataset.exe' is located (in my example, 'C:\MyTools\Showdataset\'). With your right mouse button down, drag 'Showdataset.exe' to your SendTo folder. Release your mouse button and choose 'Add shortcut here'. Rename this shortcut to an easy name, something like 'Showdataset'.

How to use this tool
Just right click on any XML file that you have created from code and choose 'Send to -> Showdataset'. If there's no error, 'Showdataset' is launched with each data table on a separate tab page. Each tab uses the internal table names as text. In the status bar, you see the table displayed, and how many records and columns are used. As you see, this is a much easier way to show you what's inside your run-time generated dataset, without the need to add breakpoints.

How the code works
Because we are working with program arguments, we need to define a static string for holding the complete file path. On top of the Form1 class, you see:
private static string docName = "";
In the main function, you see how we catch this argument by:
[STAThread]
static void Main(string[] args)
{
docName = args[0];
Application.Run(new Form1());
}
In the OnLoad event of Form1, you'll find:
if(docName.Length>0)
{
try
{
ds.ReadXml(docName);
for(int i=0; i<ds.Tables.Count; i++)
{
TabPage tab = new TabPage(ds.Tables[i].TableName);
DataGrid grid = new DataGrid();
grid.Dock = System.Windows.Forms.DockStyle.Fill;
grid.DataSource = ds.Tables[i];
tab.Controls.Add(grid);
tabControl1.TabPages.Add(tab);
}
if(ds.Tables.Count>0)tabControl1_SelectedIndexChanged(sender,e);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"Error!");
Application.Exit();
}
}
Hopefully, this tool will help you to easily navigate through runtime created datasets and/or data tables. As you can see, my screen dumps my native language Dutch, so forgive me if my English is not clear enough.
Have fun!