This tutorial is based on Visual Basic 6.0. The complete application can be found in the Visual Basic project samples-dir\SQLAnywhere\VBStarter\Starter.vbp.
Visual Basic provides several data access technologies. In this tutorial, you use the Microsoft ADO Data Control with the SQL Anywhere OLE DB provider to access the SQL Anywhere sample database from Visual Basic.
Start Visual Basic, choosing a Standard Executable project.
Add the Microsoft ADO Data Control 6.0 to your tool palette:
From the Project menu, choose Components.
Select the Microsoft ADO Data Control 6.0 component from the list.
Click OK to add the control to the Toolbox palette.
Add the ADO Data Control to the form, as follows:
From the View menu, choose Toolbox.
Click the Adodc icon in the Toolbox palette.
Draw a rectangle on the design form.
Configure the ADO Data Control:
Property |
Value |
---|---|
CommandType |
2 - adCmdTable |
ConnectionString |
Provider=SAOLEDB;DSN=SQL Anywhere 10 Demo |
CursorLocation |
2 - adUseServer |
CursorType |
2 - adOpenDynamic |
RecordSource |
Employees |
The ConnectionString uses the SQL Anywhere OLE DB Provider (SAOLEDB) to connect to the "SQL Anywhere 10 Demo" data source. The cursor settings take advantage of SQL Anywhere server-side cursors rather than using client-side cursors.
Add two text boxes to the form, as follows:
Click the TextBox icon in the Toolbox palette.
Draw a rectangle on the design form just above the Adodc1 control as shown in the diagram below.
Draw a second rectangle on the design form to the right of the first TextBox as shown in the diagram.
Bind the text boxes to the ADO Data Control:
Set the DataSource property for each to be Adodc1.
Set the DataField property for the left-hand text box to GivenName, which is the column holding the employee's first name.
Set the DataField property for the right-hand text box to Surname, which is the column holding the employee's last name.
Save the project.
Run the sample:
Choose Run > Start to run the application.
The application connects to the SQL Anywhere sample database and puts the name of the first employee in the text boxes, as follows:
You can use the buttons on the ADO Data Control to scroll through the rows of the result set.
You have now created a simple Visual Basic application that works with ADO and the SQL Anywhere OLEDB provider.