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

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - Programming » .NET application programming » .NET Data Provider tutorials

 

Tutorial: Using the Table Viewer code sample

The TableViewer project uses the .NET Data Provider to connect to a database, execute SQL statements, and display the results using a DataGrid object.

Prerequisites

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

You must have the SELECT ANY TABLE system privilege.

Context and remarks

The TableViewer project is included with the SQL Anywhere samples. The Table Viewer project is more complex than the Simple project. You can use it to connect to a database, select a table, and execute SQL statements on the database.

 Task
  1. Start Visual Studio.

  2. Click File » Open » Project.

  3. Browse to %SQLANYSAMP16%\SQLAnywhere\ADO.NET\TableViewer and open the TableViewer.sln project.

  4. To use the SQL Anywhere .NET Data Provider in a project, you must add a reference to the Data Provider DLL. This has already been done in the Table Viewer code sample. To view the reference to the Data Provider (iAnywhere.Data.SQLAnywhere), open the References folder in the Solution Explorer window.

  5. You must also add a using directive to your source code to reference the Data Provider classes. This has already been done in the Table Viewer code sample. To view the using directive:

    • Open the source code for the project. In the Solution Explorer window, right-click TableViewer.cs and click View Code.

    • In the using directives in the top section, you should see the following line:

      using iAnywhere.Data.SQLAnywhere;

      This line is required for C# projects. If you are using Visual Basic, you need to add an Imports line to your source code.

  6. Click Debug » Start Without Debugging or press Ctrl+F5 to run the Table Viewer sample.

    The application connects to the SQL Anywhere sample database.

  7. In the Table Viewer window, click Connect.

  8. In the Table Viewer window, click Execute.

    The application retrieves the data from the Employees table in the sample database and puts the query results in the Results datagrid, as follows:

    Screen shot of table viewer with the Employees table of the sample database selected.

    You can also execute other SQL statements from this application: type a SQL statement in the SQL Statement pane, and then click Execute.

  9. Close the Table Viewer window to shut down the application and disconnect from the sample database. This also shuts down the database server.

Results

You have built and executed a .NET application that uses the .NET Data Provider to connect to a database, execute SQL statements, and display the results using a DataGrid object.

Next

None.

Example

The complete application can be found in the SQL Anywhere samples directory at %SQLANYSAMP16%\SQLAnywhere\ADO.NET\TableViewer.


 See also

The Table Viewer sample project explained