Click here to Skip to main content
15,887,135 members
Articles / Programming Languages / C#

Special QuickWatch for a DataSet

Rate me:
Please Sign up or sign in to vote.
4.94/5 (106 votes)
26 May 2004CPOL2 min read 337.5K   5.1K   144   105
A VS.NET add-in to know the content of the any dataset during debugging.

Sample Image - Article.gif

Introduction

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:

C#
// 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:

C#
string fileExtintion;
TextSelection _TextSelection;

_TextSelection = (TextSelection) applicationObject.ActiveDocument.Selection;

str = _TextSelection.Text;

fileExtintion=applicationObject.ActiveDocument.FullName.Substring(
                      applicationObject.ActiveDocument.FullName.Length-2 ) ;

switch(fileExtintion.ToLower() )
    {
    case "cs":
        isDataSetExpression="(System.Data.DataSet)"+str+".Tables";
        getXmlExpression="((System.Data.DataSet)"+str+").GetXml()";
        break;

    case"vb":
        isDataSetExpression="ctype("+ str +",System.Data.DataSet).Tables";
        getXmlExpression="ctype("+ str +",System.Data.DataSet).GetXml()";
        break;
    }

//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!");
    return;
}

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

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

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.

License

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


Written By
Web Developer
Jordan Jordan
web developer
email : mohammed.barqawi AT gmail.com

Comments and Discussions

 
GeneralRe: Help, its not working! - it is now Pin
joolsb4-Jun-04 0:58
joolsb4-Jun-04 0:58 
GeneralSetup Fails Pin
ArntK3-Jun-04 20:47
ArntK3-Jun-04 20:47 
GeneralRe: Setup Fails Pin
joolsb4-Jun-04 1:00
joolsb4-Jun-04 1:00 
GeneralOne Suggestion..... Pin
dclark2-Jun-04 19:50
dclark2-Jun-04 19:50 
GeneralGreat! Pin
Member 1919242-Jun-04 16:06
Member 1919242-Jun-04 16:06 
GeneralI see the menu, but it doesn't work Pin
big_onion2-Jun-04 15:57
big_onion2-Jun-04 15:57 
GeneralRe: I see the menu, but it doesn't work Pin
Chris Wuestefeld7-Jun-04 7:24
Chris Wuestefeld7-Jun-04 7:24 
GeneralOutstanding! Pin
Robert Gibson2-Jun-04 10:52
Robert Gibson2-Jun-04 10:52 
GeneralDataTables and DataRows Pin
ferran91-Jun-04 23:44
ferran91-Jun-04 23:44 
GeneralRe: DataTables and DataRows Pin
hilite13-Jun-04 23:53
hilite13-Jun-04 23:53 
GeneralNice work! Pin
ThePhoenix1-Jun-04 23:04
ThePhoenix1-Jun-04 23:04 
GeneralBRILLIANT.. Just what the doctor ordered. Pin
dclark1-Jun-04 12:33
dclark1-Jun-04 12:33 
GeneralNon-Datasets could be serialized Pin
Lewis Moten1-Jun-04 9:42
Lewis Moten1-Jun-04 9:42 
QuestionHow do I activate this? Pin
Anonymous1-Jun-04 8:46
Anonymous1-Jun-04 8:46 
AnswerRe: How do I activate this? Pin
andrija111-Jun-04 13:47
andrija111-Jun-04 13:47 
GeneralRe: How do I activate this? Pin
mohammed barqawi1-Jun-04 21:51
mohammed barqawi1-Jun-04 21:51 
GeneralRe: How do I activate this? Pin
skempe2-Jun-04 6:53
skempe2-Jun-04 6:53 
GeneralRe: How do I activate this? Pin
Uri Dor6-Jun-04 1:24
Uri Dor6-Jun-04 1:24 
GeneralRe: How do I activate this? Pin
Anonymous2-Jun-04 8:08
Anonymous2-Jun-04 8:08 
GeneralExcellent Pin
Bee Master30-May-04 4:37
Bee Master30-May-04 4:37 
GeneralVery Good Work Pin
29-May-04 4:07
suss29-May-04 4:07 
GeneralNice job Pin
assemizm29-May-04 1:17
assemizm29-May-04 1:17 
GeneralNice idea Pin
Mike Ellison28-May-04 8:16
Mike Ellison28-May-04 8:16 
QuestionAdd-In work for VS2002? Pin
Orcrist28-May-04 7:38
Orcrist28-May-04 7:38 
AnswerRe: Add-In work for VS2002? Pin
mohammed barqawi28-May-04 18:43
mohammed barqawi28-May-04 18:43 

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.