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.
Start Visual Studio.
From the Visual Studio File menu, choose New » Project.
The New Project window appears.
In the left pane of the New Project window, choose either Visual Basic or Visual C# for the programming language.
From the Windows subcategory, choose Windows Application (VS 2005) or Windows Forms Application (VS 2008).
In the project Name field, type MySimpleViewer.
Click OK to create the new project.
In the Visual Studio View menu, choose Server Explorer.
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.
In the Add Connection window:
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.
Under Data Source, choose ODBC Data Source Name and type SQL Anywhere 12 Demo.
Click Test Connection to verify that you can connect to the sample database.
Click OK.
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 choose Show Table Data.
This shows the rows and columns of the Products table in a window.
Close the table data window.
From the Visual Studio Data menu, choose Add New Data Source.
In the Data Source Configuration Wizard, do the following:
On the Data Source Type page, choose Database and click Next.
On the Data Connection page, choose SQL Anywhere.demo12 and 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, choose Tables and click Finish.
From the Visual Studio Data menu, choose Show Data Sources.
The Data Sources window appears.
Expand the Products table in the Data Sources window.
Click Products and choose Details from the dropdown list.
Click Photo and choose 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, choose 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, choose Zoom.
To close the Picture Box Tasks window, click anywhere outside the window.
Build and run the project.
From the Visual Studio Build menu, choose Build Solution.
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.
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 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.
Shut down the application and then save your project.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |