This tutorial is based on Visual Studio and the .NET Framework. The complete application can be found in the ADO.NET project %SQLANYSAMP12%\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.
Start Visual Studio.
Click File » New » Project.
The New Project window appears.
In the left pane of the New Project window, click either Visual Basic or Visual C# for the programming language.
From the Windows subcategory, click Windows Application (VS 2005) or Windows Forms Application (VS 2008).
In the project Name field, type MySimpleViewer.
Click OK to create the new project.
Click View » Server Explorer.
In the Server Explorer window, right-click Data Connections and click Add Connection.
A new connection named SQL Anywhere.demo12 appears in the Server Explorer window.
In the Add Connection window:
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.
Under Data Source, click ODBC Data Source Name and type SQL Anywhere 12 Demo.
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.
Click Test Connection to verify that you can connect to the sample database.
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:
Right-click the Products table and click Show Table Data.
This shows the rows and columns of the Products table in a window.
Close the table data window.
Click Data » Add New Data Source.
In the Data Source Configuration Wizard, do the following:
On the Data Source Type page, click Database, then click Next.
On the Data Connection page, click SQL Anywhere.demo12, then click Next.
On the Save The Connection String page, make sure that Yes, Save The Connection As is chosen and click Next.
On the Choose Your Database Objects page, click Tables, then click Finish.
Click Data » Show Data Sources.
The Data Sources window appears.
Expand the Products table in the Data Sources window.
Click Products, then click Details from the dropdown list.
Click Photo, then click Picture Box from the dropdown list.
Click Products and drag it to your form (Form1).
A dataset control and several labeled text fields appear on the form.
On the form, click the picture box next to Photo.
Change the shape of the box to a square.
Click the right-arrow in the upper-right corner of the picture box.
The Picture Box Tasks window opens.
From the Size Mode dropdown list, click Zoom.
To close the Picture Box Tasks window, click anywhere outside the window.
Build and run the project.
Click Build » Build Solution.
Click Debug » 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.
You can use the buttons on the control to scroll through the rows of the result set.
You can go directly to a row in the result set by entering the row number in the scroll control.
You can update values in the result set using the text boxes and save them by clicking the Save Data button.
You have now created a simple, yet powerful, .NET application using Visual Studio, the Server Explorer, and the SQL Anywhere .NET Data Provider.
Shut down the application and then save your project.
Discuter à propos de cette page dans DocCommentXchange.
|Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1|