Export (0) Print
Expand All

Walkthrough: A Parameterized Query Application 

This topic has been updated for Visual Studio 2005 SP1.

This walkthrough shows you how to use the Visual Studio 2005 environment to develop a simple parameterized query application. Databinding and much of the user interface are generated for you automatically. Relying on the familiar Northwind database, this application provides for the scenario where smart device users need to determine the Shipping Country when they know only the Order Number. The application you build here provides for user input of the Order Number and the consequent display of the corresponding Shipping Country.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

This walkthrough was written using Visual Basic Development Settings and Visual C# Development Settings.

The following procedures have been updated for Visual Studio 2005 SP1.

The installed database varies according to which release of Visual Studio you have installed:

  • Microsoft SQL Server Mobile Edition (Visual Studio 2005)

  • Microsoft SQL Server 2005 Compact Edition (Visual Studio 2005 SP1)

The Northwind database for SQL Server Mobile or SQL Server Compact Edition, included in Visual Studio 2005.

NoteNote

If you are not an Administrator on your development computer, you cannot open the Northwind.sdf file in its default location, \Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0. Copy the file to the desktop or to My Documents and open it from there when you are prompted.

To ensure that you are prompted to select a device when you deploy your solution, complete the following procedure.

To prompt for device choices at deployment time

  1. On the Tools menu, click Options, click Device Tools, and then click General.

  2. Select the Show device choices before deploying a device project check box.

This is a simple Windows Forms application to host the data functionality of this walkthrough.

To create a Windows Forms device project

  1. (Visual Basic) On the File menu in Visual Studio 2005, click New Project.

    —or—

    (Visual C#) On the File menu in Visual Studio 2005, point to New, and then click Project.

  2. Under Project Types in the New Project dialog box, expand Visual Basic or Visual C#, expand Smart Device, and then click Pocket PC 2003.

    If the language you want does not at first appear, expand Other Languages. This display is governed by your development settings.

  3. Under Templates, click Device Application.

    NoteNote

    Do not select Device Application (1.0), which relies on version 1.0 of the .NET Compact Framework and is not suitable for this walkthrough.

  4. In the Name box, type ParamQuerySample.

  5. (Visual C# only) In the Location box, verify where you want to store your project files.

  6. Click OK.

    A representation of a Pocket PC device appears in the Windows Forms Designer.

This section consists of the following tasks:

  • Selecting a data source type.

  • Selecting and configuring a data connection.

  • Selecting database objects.

  • Adding data-bound controls to the form.

To select a data source type

  1. On the Data menu, click Add New Data Source to open the Data Source Configuration Wizard.

  2. On the Choose a Data Source Type page, select Database, and then click Next.

To select and configure a data connection

  1. On the Choose Your Data Connection page, click New Connection.

  2. In the Choose Data Source dialog box, select Microsoft SQL Server Mobile Edition, and then click Continue.

    —or—

    In the Choose Data Source dialog box, select Microsoft SQL Server Compact Edition, and then click Continue.

    NoteNote

    Depending on settings and previous projects, the Add Connection dialog box might appear instead of the Choose Data Source dialog box. If this happens, click Change in the Add Connection dialog box to open the Change Data Source dialog box. Then select Microsoft SQL Server Mobile Edition or Microsoft SQL Server Compact Edition, and click OK.

  3. In the Add Connection dialog box, select My Computer.

  4. Again in the Add Connection dialog box, click Browse.

  5. In the Select SQL Server Mobile Edition Database File dialog box, select Northwind.sdf, and then click Open.

    —or—

    In the Select SQL Server Compact Edition Database File dialog box, select Northwind.sdf, and then click Open.

  6. In the Add Connection dialog box, leave the Password box empty.

    This database has no password.

  7. Click Test Connection to verify the connection.

    NoteNote

    If access to the Northwind.sdf file is denied, copy the file to the desktop, and browse to that copy to open. This situation can occur if you do not have sufficient rights on the development computer to open the file in its default location, which is listed toward the beginning of this walkthrough.

  8. Click OK on the message box that shows the connection succeeded, and then click OK to close the Add Connection dialog box.

  9. Close the Choose Your Data Connection page by clicking Next.

  10. In the message box that asks whether you want to copy the file to your project, click Yes.

To select database objects

  1. On the Choose Your Database Objects page, expand the Tables node, and then select the Orders table.

  2. Click Finish.

    The NorthwindDataset is created. You can view this data source by selecting Show Data Sources on the Data menu.

To create the query

  1. In the Data Sources window, expand the Orders table.

  2. Click the Ship Country column, click the drop-down arrow, and then select the Label option.

  3. Drag the Ship Country column onto the form in the designer.

  4. On the label control in the designer, click the smart tag, and then on the shortcut menu, click Add Query.

  5. In the Search Criteria Builder dialog box, click Query Builder.

  6. In the Filter column of the Order ID row, type a question mark (?).

    This symbol indicates that users of the application will have to enter a value for Order ID.

  7. Click OK.

    The WHERE clause in the Query Text box should now read ([Order ID]=@PARAM1).

  8. Click OK to close the Search Criteria Builder dialog box.

    A panel appears on the form in the designer.

To refine the user interface

  1. Right-click the PARAM1 label control in the designer, and then on the shortcut menu, click Properties.

  2. Change the Text property to Order ID.

  3. Select the FillBy button, and then change its text property to Show country.

  4. Expand the panel and controls to eliminate the scroll bars and show all the text. Be especially careful that the Ship_CountryLabel and its text box are not hidden behind the FillByPanel and its controls.

In this section you build the application, download it to the Pocket PC 2003 SE emulator, and verify that the application works correctly.

To test the application

  1. On the Debug menu, click Start or Start Debugging.

  2. In the Deploy dialog box, select Pocket PC 2000 SE Emulator, and then click Deploy.

    Deployment progress appears in the Status bar. Deployment to the emulator can take some time.

  3. When the application is running on the emulator, type an order number, which run from 10000 to 11077 in the Northwind database, and then click Show country.

    The Ship Country for that order appears in the label control.

If you plan to do additional walkthroughs or open other projects, you want to shut down the emulator completely and exit this solution.

To close the emulator and the solution

  1. On the File menu of the emulator, click Exit.

  2. In the Device Emulator message box, click No to the message asking if you want to save the emulator state.

  3. (Visual Basic) On the File menu, click Close Project.

    —or—

    (Visual C#) On the File menu, click Close Solution.

    If you are prompted to save the project or solution, click Save if you want to use it again later; otherwise, click Discard and your files will not be saved.

Community Additions

ADD
Show:
© 2014 Microsoft