Debugging DataSets


When you’re debugging code with Visual Studio .NET, it’s really hard to see what data
is currently contained within a DataSet. Sure, the Locals window will show any DataSet
objects currently in scope, but finding out what data is contained within them is
not easy.

Two good ways of accessing this information both revolve around the XML methods available
on the object. Firstly, if you’ve got a console window associated with your application,
you can do:
   ds.WriteXml(Console.Out);
which uses the stream-based overload of the WriteXml method to dump the DataSet to
the console.

It’s even easier if you’ve got a VS.NET Command window open (hit Ctrl+Alt+A). Make
sure you’re in immediate mode by entering immed, and then simply run:
   ? ds.GetXml()
This dumps the contents of the DataSet to the Command window.


Comments (2)

  1. Anonymous says:

    That nice. What I also did was to define all kinds off DebugPrint functions in a separate class (used only for "immed" debugging. And since VS.NET is happy to execute my code I can to do things like
    ? DebugHelper.Print( myHashTable )
    ? DebugHelper.Print( myDS )

  2. Anonymous says:

    Wow…that’s awesome. Being a C++ programmer, I’ve never had the benefit of an immediate window while debugging like VB6 developers have, so this is definitely something that I’ll have to get used to. It looks like a great time saver, though, so I’ll have to remind myself to use it from time to time.