Click here to Skip to main content
14,836,067 members
Articles / Programming Languages / C#
Posted 26 May 2004


144 bookmarked

Special QuickWatch for a DataSet

Rate me:
Please Sign up or sign in to vote.
4.94/5 (105 votes)
26 May 2004CPOL2 min read
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 Pin
AMIT_BHAGAT24-Dec-14 1:38
MemberAMIT_BHAGAT24-Dec-14 1:38 
GeneralMy vote of 5 Pin
AMIT_BHAGAT24-Dec-14 1:33
MemberAMIT_BHAGAT24-Dec-14 1:33 
QuestionHow to install add-on? Pin
thanhtam2324-Feb-12 3:11
Memberthanhtam2324-Feb-12 3:11 
GeneralGreat little tool Pin
stackemedia10-Sep-09 0:30
Memberstackemedia10-Sep-09 0:30 
GeneralProblems with DsWatch in .net 2002 Pin
stvan21-May-09 8:38
Memberstvan21-May-09 8:38 
GeneralWoW!!!! Pin
pinkchand4-Apr-07 6:23
Memberpinkchand4-Apr-07 6:23 
GeneralProblem.................. Pin
fadee2-Aug-06 20:57
Memberfadee2-Aug-06 20:57 
GeneralRe: Problem.................. Pin
zipperleold6-Sep-06 21:36
Memberzipperleold6-Sep-06 21:36 
GeneralRe: Problem.................. Pin
fadee7-Sep-06 2:32
Memberfadee7-Sep-06 2:32 
GeneralRe: Problem.................. Pin
zipperleold10-Sep-06 20:56
Memberzipperleold10-Sep-06 20:56 
GeneralRe: Problem.................. Pin
fadee7-Sep-06 2:35
Memberfadee7-Sep-06 2:35 
QuestionHow to use the add-in as non-administrator account Pin
Boudino22-Jun-06 23:21
MemberBoudino22-Jun-06 23:21 
GeneralIt does not work at all Pin
Ihor Bobak1-Dec-05 9:04
MemberIhor Bobak1-Dec-05 9:04 
GeneralRe: It does not work at all Pin
Mika25-Apr-06 1:07
MemberMika25-Apr-06 1:07 
GeneralRe: It does not work at all Pin
Gerardo_19788-May-06 22:08
MemberGerardo_19788-May-06 22:08 
GeneralRe: It does not work at all Pin
Mika8-May-06 23:11
MemberMika8-May-06 23:11 
GeneralRe: It does not work at all Pin
Gerardo_19789-May-06 5:14
MemberGerardo_19789-May-06 5:14 
QuestionHow to use in VS2005 RTM Pin
groundie19-Nov-05 10:46
Membergroundie19-Nov-05 10:46 
AnswerRe: How to use in VS2005 RTM Pin
fcogarrido27-Dec-05 3:57
Memberfcogarrido27-Dec-05 3:57 
GeneralRe: How to use in VS2005 RTM Pin
fcogarrido27-Dec-05 4:19
Memberfcogarrido27-Dec-05 4:19 
GeneralRe: How to use in VS2005 RTM Pin
StillSmokin24-Jan-06 6:46
MemberStillSmokin24-Jan-06 6:46 
GeneralRe: How to use in VS2005 RTM Pin
christianArg8-Apr-08 3:26
MemberchristianArg8-Apr-08 3:26 
GeneralGood Job Pin
a123232asd21-Oct-05 21:44
Membera123232asd21-Oct-05 21:44 
GeneralGreat Job! Pin
Gerald Gibson Jr10-Oct-05 6:29
MemberGerald Gibson Jr10-Oct-05 6:29 
GeneralAnother fix - columns with all-null values disappeared Pin
Uri Dor25-Sep-05 1:27
MemberUri Dor25-Sep-05 1:27 

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

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