Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.0 » SQL Anywhere Server - Programming » .NET application programming » Tutorial: Developing a simple .NET database application with Visual Studio

 

Lesson 1: Create a table viewer

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

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

 To develop a database application with Visual Studio
  1. Start Visual Studio.

  2. From the Visual Studio File menu, choose New » Project.

    The New Project window appears.

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

    2. From the Windows subcategory, choose Windows Application (VS 2005) or Windows Forms Application (VS 2008).

    3. In the project Name field, type MySimpleViewer.

    4. Click OK to create the new project.

  3. In the Visual Studio View menu, choose Server Explorer.

  4. In the Server Explorer window, right-click Data Connections and choose Add Connection.

    A new connection named SQL Anywhere.demo12 appears in the Server Explorer window.

  5. In the Add Connection window:

    1. If you have never used Add Connection for other projects, then you will see a list of data sources. Choose 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, choose ODBC Data Source Name and type SQL Anywhere 12 Demo.

      The Add Connection window with ODBC Data Source name chosen.
    3. Click Test Connection to verify that you can connect to the sample database.

    4. Click OK.

  6. Expand the SQL Anywhere.demo12 connection in the Server Explorer window until you see the table names. If you are using Visual Studio 2005, then try the following:

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

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

    2. Close the table data window.

  7. From the Visual Studio Data menu, choose Add New Data Source.

  8. In the Data Source Configuration Wizard, do the following:

    1. On the Data Source Type page, choose Database and click Next.

    2. On the Data Connection page, choose SQL Anywhere.demo12 and click Next.

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

    4. On the Choose Your Database Objects page, choose Tables and click Finish.

  9. From the Visual Studio Data menu, choose Show Data Sources.

    The Data Sources window appears.

    Expand the Products table in the Data Sources window.

    1. Click Products and choose Details from the dropdown list.

    2. Click Photo and choose 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, choose 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, choose Zoom.

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

  11. Build and run the project.

    1. From the Visual Studio Build menu, choose Build Solution.

    2. From the Visual Studio Debug menu, choose Start Debugging.

      The application connects to the SQL Anywhere 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 diskette icon.

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

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