UltraLite for MobileVB User's Guide
Tutorial: An UltraLite for MobileVB Application for Palm OS
Lesson 3: Write connection, synchronization, and table code
In this application, you connect to the database in the Form Load event.
Write code to connect to the UltraLite database
Specify the connection parameters.
Add a ULConnectionParms control to your form. The ULConnectionParms control is a database icon on the toolbox.
In the Properties window, specify the following ULConnectionParms properties:
Property | Value |
---|---|
DatabaseOnDesktop | c:\tutorial\mvb\tutCustomer.udb |
DatabaseOnPalm | Syb3 |
SchemaOnDesktop | c:\tutorial\mvb\tutCustomer.usm |
SchemaOnPalm | tutcustomer |
Declare global UltraLite objects.
Enter the following code at the top of the form in the declarations area. This code declares the UltraLite objects you will need in this sample.
Public DatabaseMgr As New ULDatabaseManager Public Connection As ULConnection Public CustomerTable As ULTable
These variables are used through the application. Note that the DatabaseMgr variable is also allocated as a new object.
Add the code to connect to the database in the Form Load event.
The code below opens the connection to the database and if the database is new, it assigns a schema to it.
Sub Form_Load() On Error Resume Next Set Connection = _ DatabaseMgr.OpenConnectionWithParms( _ ULConnectionParms1) If Err.Number = ULSQLCode.ulSQLE_NOERROR Then MsgBox "Connected to an existing database" ElseIf Err.Number = _ ULSQLCode.ulSQLE_ULTRALITE_DATABASE_NOT_FOUND _ Then Err.Clear Set Connection = _ DatabaseMgr.CreateDatabaseWithParms( _ ULConnectionParms1) If Err.Number = ULSQLCode.ulSQLE_NOERROR _ Then MsgBox "Connected to a new database" Else MsgBox Err.Description End If Else MsgBox Err.Description End If End Sub
This code attempts to connect to an existing database. If the database does not exist, it creates a new database from the schema file and establishes a connection.
Write the code that ends the application and closes the connection when the End button is clicked:
Sub btnDone_Click() Connection.Close End End Sub
Run the application in the development environment.
Choose Run
The first time you run the application, a message box is displayed with the message Connected to a new database
. On subsequent runs the message is Connected to an existing database
. The Form then loads.
Click End to terminate the application.
You have now written a routine to establish a connection to a database. The next lesson describes how to access data.