Click here to Skip to main content
15,887,214 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

 
Generalproposed fix for "root invalid " error Pin
Uri Dor21-Sep-05 22:38
Uri Dor21-Sep-05 22:38 
GeneralWant your advise Pin
Mo7ammed_Farid15-Jul-05 5:39
sussMo7ammed_Farid15-Jul-05 5:39 
GeneralGreat Tool... Pin
fadee8-Apr-05 22:49
fadee8-Apr-05 22:49 
QuestionFour Sex's? Pin
Magadass30-Mar-05 9:05
Magadass30-Mar-05 9:05 
AnswerRe: Four Sex's? Of course! Pin
DavidNohejl30-Mar-05 9:55
DavidNohejl30-Mar-05 9:55 
AnswerRe: Four Sex's? Pin
mohammed barqawi1-Apr-05 18:40
mohammed barqawi1-Apr-05 18:40 
QuestionHow's it work? Pin
Michael Wagner29-Oct-04 8:39
Michael Wagner29-Oct-04 8:39 
GeneralDebug doesn't work at all :( Pin
binolino17-Oct-04 23:50
binolino17-Oct-04 23:50 
GeneralRe: Debug doesn't work at all :( Pin
mohammed barqawi19-Oct-04 7:53
mohammed barqawi19-Oct-04 7:53 
GeneralRe: Debug doesn't work at all :( Pin
binolino19-Oct-04 8:25
binolino19-Oct-04 8:25 
QuestionGreat Job ! How about C++ ? Pin
Member 5703478-Oct-04 19:12
Member 5703478-Oct-04 19:12 
GeneralTyped DataSet Pin
cSharpBastard6-Oct-04 1:59
cSharpBastard6-Oct-04 1:59 
GeneralRe: Typed DataSet Pin
mohammed barqawi6-Oct-04 3:15
mohammed barqawi6-Oct-04 3:15 
GeneralRe: Typed DataSet Pin
cSharpBastard6-Oct-04 4:50
cSharpBastard6-Oct-04 4:50 
QuestionDoes this work with ASP.NET programs? Pin
Jefferys19-Sep-04 8:02
Jefferys19-Sep-04 8:02 
AnswerRe: Does this work with ASP.NET programs? Pin
Jefferys19-Sep-04 11:18
Jefferys19-Sep-04 11:18 
GeneralDataTable view Pin
Jan Sotola26-Aug-04 22:46
Jan Sotola26-Aug-04 22:46 
GeneralRe: DataTable view Pin
Anonymous15-Nov-04 5:10
Anonymous15-Nov-04 5:10 
GeneralRe: DataTable view Pin
Luis Alonso Ramos30-May-05 7:52
Luis Alonso Ramos30-May-05 7:52 
GeneralRe: DataTable view Pin
José Joye15-Jun-05 19:53
José Joye15-Jun-05 19:53 
AnswerRe: DataTable view Pin
Fabrizzio6-Jul-07 4:29
Fabrizzio6-Jul-07 4:29 
GeneralXML Quick Watch... Pin
benny 2k129-Jul-04 23:19
benny 2k129-Jul-04 23:19 
GeneralProblem With GetExpression and Speed Pin
Haiping Jia27-Jul-04 9:44
Haiping Jia27-Jul-04 9:44 
GeneralRe: Problem With GetExpression and Speed Pin
mohammed barqawi9-Jul-04 21:40
mohammed barqawi9-Jul-04 21:40 
GeneralRe: Problem With GetExpression and Speed Pin
Haiping Jia12-Jul-04 5:50
Haiping Jia12-Jul-04 5:50 

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.