Share via


Using the Watch Window

Feature Only in Enterprise Edition   SQL source code debugging is supported only in Visual C++ Enterprise Edition. For more information, see .

Use the Watch window to specify local or global variables that you want to watch while debugging your program. You can also use this window to modify the values of local variables, but not global variables.

The Watch window contains four tabs: Watch1, Watch2, Watch3, and Watch4—Each tab displays a user-specified list of variables in a spreadsheet field. You can group variables that you want to watch together onto the same tab. For example, you could put variables related to a specific window on one tab and variables related to a dialog box on another tab. You could watch the first tab while debugging the window and the second tab while debugging the dialog box.

To add a variable to the Watch window

  1. From the View menu, click Debug Windows and Watch.

    The Watch window appears.

  2. Choose a tab for the variable.

  3. Type, paste, or drag the variable name into the Name column on the tab.

  4. Press ENTER.

    The Watch window evaluates the variable immediately and displays the value or an error message. The Watch window displays values in their native SQL format.

Tip   The Watch window does not display variable type information, but you can show variable type information by using the window’s property page.

To view type information for a variable

  1. In the Watch window, select the line containing the variable whose type you want to see.

  2. Click the right mouse button in the Watch window and click Properties from the shortcut menu.

    – or –

    From the View menu, click Properties.

To remove a variable from the Watch window

  1. In the Watch window, select the line containing the variable you want to remove.

  2. Press DELETE.

When the program is paused at a breakpoint or between steps, you can change the value of any local variable in your program. This gives you the flexibility to try out changes and see their results in real time, or to recover from certain logic errors.

To modify the value of a variable using the Watch window

  1. In the Watch window, double-click the value.

    – or –

    Use the TAB key to move the insertion point to the value you want to modify.

  2. Type the new value, and press ENTER.

Note   You can’t modify image, text, or datetime data types. String variables (varchar) cannot be made longer.

Note   Modified cached values may not take effect while you’re stepping through the SQL statement. Although you may have modified the value, it may never be checked again during the current debugging session. There is no way to force a refresh.