Lesson 1: Creating a Table Viewer

In this lesson, you use Microsoft Visual Studio, the Server Explorer, and the SAP Sybase IQ .NET Data Provider to create an application that accesses one of the tables in the SAP Sybase IQ sample database, allowing you to examine rows and perform updates.

Prerequisites

You must have Visual Studio and the .NET Framework installed on your computer.

This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Developing a simple .NET database application with Visual Studio.

Task

This tutorial is based on Visual Studio and the .NET Framework. The complete application can be found in the ADO.NET project %ALLUSERSPROFILE%\SybaseIQ\samples\SQLAnywhere\ADO.NET\SimpleViewer\SimpleViewer.sln.

  1. Start Visual Studio.
  2. Click File » New » Project.

    The New Project window appears.

    1. In the left pane of the New Project window, click either Visual Basic or Visual C# for the programming language.

    2. From the Windows subcategory, click Windows Application (VS 2005) or Windows Forms Application (VS 2008/2010).

    3. In the project Name field, type MySimpleViewer.

    4. Click OK to create the new project.

  3. Click View » Server Explorer.
  4. In the Server Explorer window, right-click Data Connections and click Add Connection.
  5. In the Add Connection window:
    1. If you have never used Add Connection for other projects, then you see a list of data sources. Click SQL Anywhere from the list of data sources presented.

      If you have used Add Connection before, then click Change to change the data source to SQL Anywhere.

    2. Under Data Source, click ODBC Data Source Name and type Sybase IQ Demo.

      Note: When using the Visual Studio Add Connection wizard on 64-bit Windows, only the 64-bit System Data Source Names (DSN) are included with the User Data Source Names. Any 32-bit System Data Source Names are not displayed. In Visual Studio's 32-bit design environment, the Test Connection button will attempt to establish a connection using the 32-bit equivalent of the 64-bit System DSN. If the 32-bit System DSN does not exist, the test will fail.
    3. Click Test Connection to verify that you can connect to the sample database.

    4. Click OK.

    A new connection named Sybase IQ.demo appears in the Server Explorer window.

  6. Expand the Sybase IQ.demo connection in the Server Explorer window until you see the table names.

    (Visual Studio 2005 only) Try the following:

    1. Right-click the Products table and click Show Table Data.

      This shows the rows and columns of the Products table in a window.

    2. Close the table data window.

  7. Click Data » Add New Data Source.
  8. In the Data Source Configuration Wizard, do the following:
    1. On the Data Source Type page, click Database, then click Next.

    2. (Visual Studio 2010 only) On the Database Model page, click Dataset, then click Next.

    3. On the Data Connection page, click Sybase IQ.demo, then click Next.

    4. On the Save The Connection String page, make sure that Yes, Save The Connection As is chosen and click Next.

    5. On the Choose Your Database Objects page, click Tables, then click Finish.

  9. Click Data » Show Data Sources.

    The Data Sources window appears.

    Expand the Products table in the Data Sources window.

    1. Click Products, then click Details from the dropdown list.

    2. Click Photo, then click Picture Box from the dropdown list.

    3. Click Products and drag it to your form (Form1).


    
        Form1 displays a control and several labeled text fields.

    A dataset control and several labeled text fields appear on the form.

  10. On the form, click the picture box next to Photo.
    1. Change the shape of the box to a square.

    2. Click the right-arrow in the upper-right corner of the picture box.

      The Picture Box Tasks window opens.

    3. From the Size Mode dropdown list, click Zoom.

    4. To close the Picture Box Tasks window, click anywhere outside the window.

  11. Build and run the project.
    1. Click Build » Build Solution.

    2. Click Debug » Start Debugging.

      The application connects to the SAP Sybase IQ sample database and displays the first row of the Products table in the text boxes and picture box.


      
          The application, with a row in the Products table displayed.
    3. You can use the buttons on the control to scroll through the rows of the result set.

    4. You can go directly to a row in the result set by entering the row number in the scroll control.

    5. You can update values in the result set using the text boxes and save them by clicking the Save Data button.

  12. Shut down the application and then save your project.

You have now created a simple, yet powerful, .NET application using Visual Studio, the Server Explorer, and the SAP Sybase IQ .NET Data Provider.

Next

In the next lesson, you add a datagrid control to the form developed in this lesson.