Click here to Skip to main content
Click here to Skip to main content

Special QuickWatch for a DataSet

, 26 May 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
A VS.NET add-in to know the content of the any dataset during debugging.

Sample Image - Article.gif


I am working on an ERP that is dealing with datasets a lot, and every time I need to know the contents of the dataset during debugging I try to make a quick watch but it has caused me headaches so I decided to make my own dataset quick watch.

How does it work?

I wrote my code using C#. I started by creating an Extensibility Projects from VS.NET's New Project menu. The wizard shows up and now the main idea behind this addin is how to pass an object from the VS.NET debug mode to the add-in. I did a lot of search but I did not find anything. The only way to know what is going in the debug mode is to use DTE.Debugger.GetExpression.

How did I insert my button in the context menu?

The wizard adds the created button (Command) in the Tools menu so I need to change the Tools to the context menu and to do that I replaced the Tools with Code Window, noting that the status for the command is (int)vsCommandStatus.vsCommandStatusUnsupported +(int)vsCommandStatus.vsCommandStatusInvisible to show it just when I need it:

// add the command to the right click context menu 
// note that when I insert the command it's inserted disabled
// "(int)vsCommandStatus.vsCommandStatusUnsupported +
// (int)vsCommandStatus.vsCommandStatusInvisible"

Command command = commands.AddNamedCommand ( addInInstance, DSWatchNode ,
        DataSet Quick Watch, DataSet Quick Watch, true, 60, ref contextGUIDS,
        (int)vsCommandStatus.vsCommandStatusUnsupported +
        (int)vsCommandStatus.vsCommandStatusInvisible ); 
CommandBar commandBar = (CommandBar)commandBars[Code Window]; 
CommandBarControl commandBarControl = command.AddControl(commandBar, 1); 
I have found a great article talking about addin and context menu in code project written by Erick Sgarbi called strongly typed collection and it was very useful

How to know if the selected test is a dataset?

After capturing the selected text i can use it as an expression in the Debugger.GetExpression() method of the application and evaluate anything I want. Now I will try to cast the selected text to dataset by evaluating the following:

string fileExtintion;
TextSelection _TextSelection;

_TextSelection = (TextSelection) applicationObject.ActiveDocument.Selection;

str = _TextSelection.Text;

                      applicationObject.ActiveDocument.FullName.Length-2 ) ;

switch(fileExtintion.ToLower() )
    case "cs":

        isDataSetExpression="ctype("+ str +",System.Data.DataSet).Tables";
        getXmlExpression="ctype("+ str +",System.Data.DataSet).GetXml()";

//cast the selcted text to dataset 
expr = debugger.GetExpression(isDataSetExpression,true,500);

if (expr.Value.IndexOf("error:")>-1)
    System.Windows.Forms.MessageBox.Show("This is not a DataSet!");

If the expr object does not have error message it will be a dataset:

if (expr.Value.IndexOf(error:)>-1) 
    System.Windows.Forms.MessageBox.Show(this is not DataSet!!);

How to get the content of the dataset?

I could not get the object from the debugging project so I have to know the selected dataset XML contents by evaluating selectetDataSet.GetXML.

Using the code

Run the add-in setup file and after installing the add-in you will be able to watch any dataset by selecting it in the debug mode and choosing "DataSet Quick Watch" from right-click menu.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

mohammed barqawi
Web Developer
Jordan Jordan
web developer
email : mohammed.barqawi AT

Comments and Discussions

GeneralVery Nice & Useful Tool PinmemberAMIT_BHAGAT24-Dec-14 2:38 
GeneralMy vote of 5 PinmemberAMIT_BHAGAT24-Dec-14 2:33 
QuestionHow to install add-on? Pinmemberthanhtam2324-Feb-12 4:11 
GeneralGreat little tool PinmemberMember 388061210-Sep-09 1:30 
GeneralProblems with DsWatch in .net 2002 Pinmemberstvan21-May-09 9:38 
GeneralWoW!!!! Pinmemberpinkchand4-Apr-07 7:23 
GeneralProblem.................. Pinmemberfadee2-Aug-06 21:57 
GeneralRe: Problem.................. Pinmemberzipperle6-Sep-06 22:36 
GeneralRe: Problem.................. Pinmemberfadee7-Sep-06 3:32 
GeneralRe: Problem.................. Pinmemberzipperle10-Sep-06 21:56 
GeneralRe: Problem.................. Pinmemberfadee7-Sep-06 3:35 
QuestionHow to use the add-in as non-administrator account PinmemberBoudino23-Jun-06 0:21 
GeneralIt does not work at all PinmemberIhor Bobak1-Dec-05 10:04 
GeneralRe: It does not work at all PinmemberMika25-Apr-06 2:07 
GeneralRe: It does not work at all PinmemberGerardo_19788-May-06 23:08 
GeneralRe: It does not work at all PinmemberMika9-May-06 0:11 
GeneralRe: It does not work at all PinmemberGerardo_19789-May-06 6:14 
QuestionHow to use in VS2005 RTM Pinmembergroundie19-Nov-05 11:46 
AnswerRe: How to use in VS2005 RTM Pinmemberfcogarrido27-Dec-05 4:57 
GeneralRe: How to use in VS2005 RTM Pinmemberfcogarrido27-Dec-05 5:19 
GeneralRe: How to use in VS2005 RTM Pinmemberjason@myveryownwebsite.com24-Jan-06 7:46 
GeneralRe: How to use in VS2005 RTM PinmemberchristianArg8-Apr-08 4:26 
GeneralGood Job PinsussHamrosh ....:)21-Oct-05 22:44 
GeneralGreat Job! PinmemberGerald Gibson Jr10-Oct-05 7:29 
GeneralAnother fix - columns with all-null values disappeared PinmemberUri Dor25-Sep-05 2:27 
Generalproposed fix for "root invalid " error PinmemberUri Dor21-Sep-05 23:38 
GeneralWant your advise PinsussMo7ammed_Farid15-Jul-05 6:39 
GeneralGreat Tool... Pinmemberfadee8-Apr-05 23:49 
QuestionFour Sex's? PinmemberMagadass30-Mar-05 10:05 
AnswerRe: Four Sex's? Of course! Pinmemberdnh30-Mar-05 10:55 
AnswerRe: Four Sex's? Pinmembermohammed barqawi1-Apr-05 19:40 
QuestionHow's it work? PinmemberMichael Wagner29-Oct-04 9:39 
GeneralDebug doesn't work at all :( Pinmemberbinolino18-Oct-04 0:50 
GeneralRe: Debug doesn't work at all :( Pinmembermohammed barqawi19-Oct-04 8:53 
GeneralRe: Debug doesn't work at all :( Pinmemberbinolino19-Oct-04 9:25 
QuestionGreat Job ! How about C++ ? Pinmembersrinup8-Oct-04 20:12 
GeneralTyped DataSet PinmembercSharpBastard6-Oct-04 2:59 
GeneralRe: Typed DataSet Pinmembermohammed barqawi6-Oct-04 4:15 
GeneralRe: Typed DataSet PinmembercSharpBastard6-Oct-04 5:50 
QuestionDoes this work with ASP.NET programs? PinmemberJefferys19-Sep-04 9:02 
AnswerRe: Does this work with ASP.NET programs? PinmemberJefferys19-Sep-04 12:18 
GeneralDataTable view PinsussJan Sotola26-Aug-04 23:46 
GeneralRe: DataTable view PinsussAnonymous15-Nov-04 6:10 
GeneralRe: DataTable view PinmemberLuis Alonso Ramos30-May-05 8:52 
GeneralRe: DataTable view PinmemberJosé Joye15-Jun-05 20:53 
AnswerRe: DataTable view PinmemberFabrizzio6-Jul-07 5:29 
GeneralXML Quick Watch... Pinmemberbenny 2k130-Jul-04 0:19 
GeneralProblem With GetExpression and Speed PinmemberHaiping Jia27-Jul-04 10:44 
GeneralRe: Problem With GetExpression and Speed Pinmembermohammed barqawi9-Jul-04 22:40 
GeneralRe: Problem With GetExpression and Speed PinmemberHaiping Jia12-Jul-04 6:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150327.1 | Last Updated 27 May 2004
Article Copyright 2004 by mohammed barqawi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid