Click here to Skip to main content
15,887,267 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: Problem With GetExpression and Speed Pin
mohammed barqawi14-Jul-04 2:49
mohammed barqawi14-Jul-04 2:49 
GeneralRe: Problem With GetExpression and Speed Pin
Haiping Jia215-Jul-04 9:22
Haiping Jia215-Jul-04 9:22 
GeneralRe: Problem With GetExpression and Speed Pin
mohammed barqawi16-Jul-04 19:37
mohammed barqawi16-Jul-04 19:37 
GeneralRe: Problem With GetExpression and Speed Pin
Haiping Jia211-Aug-04 9:40
Haiping Jia211-Aug-04 9:40 
GeneralGeat News Pin
Haiping Jia217-Aug-04 5:16
Haiping Jia217-Aug-04 5:16 
GeneralRe: Geat News Pin
mohammed barqawi17-Aug-04 6:27
mohammed barqawi17-Aug-04 6:27 
GeneralRe: Geat News Pin
Haiping Jia217-Aug-04 10:09
Haiping Jia217-Aug-04 10:09 
GeneralRe: Problem With GetExpression and Speed Pin
Member 22013906-Oct-05 7:02
Member 22013906-Oct-05 7:02 
QuestionHow can I debug the project? Pin
Haiping Jia224-Jun-04 9:07
Haiping Jia224-Jun-04 9:07 
AnswerRe: How can I debug the project? Pin
Haiping Jia225-Jun-04 4:00
Haiping Jia225-Jun-04 4:00 
GeneralRe: How can I debug the project? Pin
mohammed barqawi25-Jun-04 20:50
mohammed barqawi25-Jun-04 20:50 
GeneralRe: How can I debug the project? Pin
Haiping Jia28-Jun-04 4:03
Haiping Jia28-Jun-04 4:03 
GeneralThis doesn't work on my VS2003 Pin
Rogic9-Jun-04 5:10
Rogic9-Jun-04 5:10 
QuestionHow about Diffgrams? Pin
Bydia8-Jun-04 15:28
Bydia8-Jun-04 15:28 
AnswerRe: How about Diffgrams? Pin
mohammed barqawi9-Jun-04 0:24
mohammed barqawi9-Jun-04 0:24 
QuestionDoes it work on Visual Studio 2002? Pin
Alexandru Savescu8-Jun-04 2:51
Alexandru Savescu8-Jun-04 2:51 
AnswerRe: Does it work on Visual Studio 2002? Pin
mohammed barqawi8-Jun-04 22:23
mohammed barqawi8-Jun-04 22:23 
AnswerRe: Does it work on Visual Studio 2002? Pin
amitmerla8-Jun-04 22:26
amitmerla8-Jun-04 22:26 
GeneralErrors on Some Datasets Pin
wadeleverett4-Jun-04 4:46
wadeleverett4-Jun-04 4:46 
GeneralRe: Errors on Some Datasets Pin
majohnson7-Jul-04 6:35
majohnson7-Jul-04 6:35 
GeneralRe: Errors on Some Datasets Pin
mohammed barqawi9-Jul-04 21:31
mohammed barqawi9-Jul-04 21:31 
QuestionOnly displays 1 table? Pin
etechpartner4-Jun-04 3:15
etechpartner4-Jun-04 3:15 
GeneralThank you and a question Pin
Big Cheese4-Jun-04 3:15
Big Cheese4-Jun-04 3:15 
GeneralVery useful...Good work Pin
rkfdsam4-Jun-04 2:56
rkfdsam4-Jun-04 2:56 
GeneralHelp, its not working! Pin
joolsb3-Jun-04 21:47
joolsb3-Jun-04 21:47 

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.