Basic4ppc SQL library reference

◄   Previous page         Table of Contents          Next page  ►

Basic4ppc  Home  |  Forum

 

Step 2 - create and connect to a database

 

This part assumes you have added SQLite support to your application as described in the previous page. It goes on with developing the sample application.

 

 

Sub CreateConnection

2       Connection.New1

3       Command.New1("", Connection.Value)

4       Connection.Open("Data Source = " & AppPath & "\Rest.lit")

End Sub

 

 

 

Add the code above at the end of your program, below the End Sub of the Sub App_Start

 

These lines of code form the basic connection to the database:

 

Of course, after the first time you have created the database there is no need to create it anymore. This code either create a database and connects to is, or just connects to it, if it already exists.

 

After writing this Sub, add a call to the sub in the App_Start Sub as follows:

 

Sub App_Start

    CreateConnection

    Form1.Show   

End Sub

 

 

This ensures the newly-created Sub (CreateConnection) will be called when the program starts.

We also have to make sure we close the connection when the program ends, typically when the main form (Form1 in our example) is closed.

 

Add the following code:

 

Sub Form1_Close

    Con.Close

End Sub

 

 

These are the actions required to open a connection. Next we shall create the tables.

 

 

Next page: Step 3: Creating the database tables.

Basic4ppc SQL library reference

◄   Previous page         Table of Contents          Next page  ►

Basic4ppc  Home  |  Forum