This tutorial is based on the Table Viewer project that is included with the SQL Anywhere .NET Data Provider.
The complete application can be found in your SQL Anywhere samples directory in samples-dir\SQLAnywhere\ADO.NET\TableViewer.
For information about the default location of samples-dir, see Samples directory.
The Table Viewer project is more complex than the Simple project. It illustrates the following features:
connecting to a database using the SAConnection object
executing a query using the SACommand object
obtaining the results using the SADataReader object
using a grid to display the results using the DataGrid object
more advanced error handling and result checking
For more information about how the sample works, see Understanding the Table Viewer sample project.
Start Visual Studio.
Choose File » Open » Project.
Browse to samples-dir\SQLAnywhere\ADO.NET\TableViewer and open the TableViewer.sln project.
If you want 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. You can view the reference to the Data Provider DLL in the following location:
In the Solution Explorer window, open the References folder.
You should see iAnywhere.Data.SQLAnywhere in the list.
For instructions about adding a reference to the Data Provider DLL, see Adding a reference to the Data Provider DLL in your project.
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
Open the source code for the project. In the Solution Explorer window, right-click TableViewer.cs and choose View Code.
using directives in the top section, you should see the following line:
This line is required for C# projects. If you are using Visual Basic, you need to add an
Imports line to your source code.
Choose Debug » Start Without Debugging or press Ctrl+F5 to run the Table Viewer sample.
The application connects to the SQL Anywhere sample database.
In the Table Viewer window, click Connect.
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:
You can also execute other SQL statements from this application: type a SQL statement in the SQL Statement pane, and then click Execute.
In the upper right corner of the window, click X to shut down the application and disconnect from the SQL Anywhere sample database. This also shuts down the database server.
You have now run the application. The next section describes the application code.
|Envoyer votre avis sur cette page par email.||Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1|