Creating Database Projects with SQL Anywhere Studio, Part 2 - Creating a VB application
(Page 4 of 5 )
There are several ways to create a data project within VB 6.0. The method demonstrated here is one of rapidly prototyping the application. Start Adaptive Server Anywhere as discussed earlier (double clicking the shortcut in the Start->Programs). Start a vb Standard Exe project. From main menu->Project, click and select AddDataEnvironment. This adds an icon DataEnvironment1 to the DataEnvironment objects pane and an item(Connection1) to the Project folder as shown in the next two pictures.


Right Click the Connection1 in the Designer's pane and view its properties. It opens up the Data Link Properties with Microsoft OLEDB for ODBC as the provider.

In the Connection tab of the Data Link properties, you should be able to pick up Asa 9.0 Sample; for the authentication, use dba for User Name and sql for password. Test the connection.


The connection string can now be seen in the Connection1's property window, reproduced here: Provider=MSDASQL.1;Persist Security Info=False;User ID=dba;Data Source=ASA 9.0 Sample
Now right click the Connection1 in the Designer's plane and pick AddCommand. This adds a default Command1 (you may rename most of the defaults).

Right click the Command1 added, to view its properties. It opens up Command1's properties page window with six tabs: General, Parameters, Relation, Grouping, Aggregates, and Advanced. The Connection text box will be showing Connection1. The Command Name text box will be showing the Command1 you are trying to set up.
For the Source of Data object's drop down list, you have couple of choices: Stored Procedures, Table, View, and Synonym. For the chosen database object the next drop-down shows the object Name. Should your choice be Tables, the drop down shows all the tables, etc. If you want to write your own SQL statement, then you choose the SQL Statement Radio button. From here on, either you can type in the statement, or build the statement using the query builder, a builder that can be accessed from within VB. In this particular case, since this article is not a tutorial on how to build queries or create a complete application, a table database object is chosen for simplicity.

Finally, highlight the Command1 object in the designer's plane and drag it on to form1. The whole table with all the columns will be placed on the form.

Now add a button to the bottom of this form with Caption as "Next", and Name as cmdNext. To the click event of the cmdNext button add the following code:
Private Sub cmdNext_Click()
If Not DataEnvironment1.rsCommand1.EOF Then
DataEnvironment1.rsCommand1.MoveNext
End If
End Sub
Now save the project and run. With this, the rows in the table can be moved in the "Next" direction. You could add other buttons to create a navigation set, or you can add buttons and code to manipulate the data in the database. Since this is only an example of connecting to Adaptive Server Anywhere, only the steps necessary to create a single movement are shown.

Next: An example of ADO.NET application >>
More Database Articles
More By Jayaram Krishnaswamy