SQL Anywhere Version 9.0: Ianywhere Solutions, A Subsidiary of Sybase, Inc
SQL Anywhere Version 9.0: Ianywhere Solutions, A Subsidiary of Sybase, Inc
0
ASP.NET / ADO.NET Tutorial
For Visual Studio .NET
iAnywhere Solutions,
a subsidiary of Sybase, Inc.
Copyright © iAnywhere Solutions 2003
Overview
This tutorial is intended to give a brief understanding on how to use ASP.NET to
access an Adaptive Server Anywhere 9.0 database using ADO.NET. For this
tutorial Visual Studio .NET 2002 or 2003 can be used. Specifically, VB.NET will
be the development tool. In this tutorial we will walk through all of the steps
required to build a sample ASP.NET application to query the Adaptive Server
Anywhere database and return the results into a list box all within the Browser.
Requirements:
• Microsoft IIS
Walkthrough
1. From the Administrative Tools menu on the Web server computer' Start
menu, choose Internet Information Services.
2. Open the node for the current computer, and then open the node for Web
Sites.
3. Select Default Web Site and in the toolbar click the Start item button.
1
Copyright © iAnywhere Solutions 2003
3) This will start up the Adaptive Server Anywhere sample database and
engine.
3) Click on Add
b. Password: sql
7) Click the Database tab and enter the following: (NOTE: if you installed
Adaptive Server Anywhere 9.0 to a non-default location the Database file
may be different than below):
8) Click on the ODBC tab and click ‘Test Connection’ to ensure that the
settings are correct.
2
Copyright © iAnywhere Solutions 2003
3) As shown below, click on the ‘Visual Basic Projects’ folder and then
choose the ‘ASP.NET Web Application’ template. In the Location enter it
should point to http://location/WebApplication1. This is where VS.NET
will deploy this web application.
4) Click OK to have VS.NET create the template application. This will also
create a directory called WebApplication1 within your MS IIS directory.
Most likely c:\inetpub\wwwroot.
6) Drag a button on to the grid and then drag a list box to the grid layout.
Resize the list box to be a little larger than default such that it will look
something like the
3
Copyright © iAnywhere Solutions 2003
following:
4
Copyright © iAnywhere Solutions 2003
10) Go back to the Grid Layout and Double Click on the Button to view the
code and create a Button1_Click subroutine.
5
Copyright © iAnywhere Solutions 2003
12) If you review the code you will notice the first thing that happens is an
ADO.NET connection is opened to the Adaptive Server Anywhere
database using the parameters specified in the WebSample System data
source. Next it executes the query “Select emp_lname from employee”.
The results from the query and then read in line-by-line and added to the
list box. When there are no more rows the reader and the connection is
closed. There is also some error handling in this code that will catch
various errors. You may wish to add some custom logic to handle these
errors.