PreviousOLE DB Provider Guide ( revision 1) Next

Setting up Visual Basic for Pervasive.SQL OLE DB Programming

Show this topic in Library frames

This section helps you to integrate the Pervasive OLE DB provider into your Visual Basic development environment.

Non-Visual Programming

This procedure shows how to program in ADO and OLE DB without using the visual control objects.

To program for OLE DB in Visual Basic:

  1. Open a new project in VB 6
  2. Click on the Project|References menu item to bring up the references dialog
  3. Make sure that "Microsoft ActiveX Data Objects 2.1 Library" or "Microsoft ActiveX Data Objects 2.5 Library" is checked and press "OK"
  4. Add three textboxes to the form
  5. Bring up the code window and dimension and allocate a global recordset object using the following code (this should go in the General::Declarations code area):
  6. Dim myData as New ADODB.Recordset 
    
  7. To have the recordset created on Form::Load, put the following code in the Form_Load event (we've set up DemoData as a DBNAMES entry, and we're going to use the Person file):
  8. myData.CursorLocation = adUseServer 
    myData.Open "Person", "Provider=PervasiveOLEDB;Data 
    Source=DemoData", adOpenDynamic,    
    adLockOptimistic, adCmdTableDirect 
    
  9. We're going to want to display the records we find, so create the following subroutine:
  10. Private Sub DisplayFields() 
       Text1 = myData.Fields(0) 
       Text2 = myData.Fields(1) 
       Text3 = myData.Fields(2) 
    End Sub 
    
  11. Add 4 buttons to the form, and add the following code:
  12. Private Sub Command1_Click() 
       myData.MoveFirst 
       DisplayFields 
    End Sub 
    Private Sub Command2_Click() 
       myData.MovePrevious 
       DisplayFields 
    End Sub 
    Private Sub Command3_Click() 
       myData.MoveNext 
       DisplayFields 
    End Sub 
    Private Sub Command4_Click() 
       myData.MoveLast 
       DisplayFields 
    End Sub 
    

  1. To get the first record when the form loads, add the following as the last line in Form_Load:
  2. Command1_Click 
    
  3. Run the application, and you will be able to use the buttons to navigate through the data. You may want to change the button captions and names to make things easier to see.
  4. To add update capabilities, place another button on the form and give it the caption "Update" and the name "btnUpdate"
  5. Add the following code so users cannot update the first field. Since the concurrency mode is adLockOptimistic, the update is applied automatically when the cursor moves off the current row. The update may also be used to force an update regardless of cursor position.
  6. Private Sub btnUpdate_Click() 
       myData.Fields(1) = Text2 
       myData.Fields(2) = Text3 
    End Sub 
    

Visual Programming

The Pervasive provider has one property that is essential for initialization, and that is Data Source. OLE DB providers do not use DSN's, so the Data Source property should be set to a DBNames value. For example, the connection string for an ADO Connection::Open command would be "Provider=PervasiveOLEDB;Data Source=<data store>", where <data store> is a DBName.

To use the provider to fill a grid in Visual Basic:

  1. Start Visual Basic 6
  2. Begin a standard project
  3. Click the Project | Components menu option to display the components dialog.
  4. Select the checkboxes next to the following components and and click OK.
    • "Microsoft ADO Data Control 6.0 (OLEDB)"
    • "Microsoft DataGrid Control 6.0 (OLEDB)"
  5. Drag and drop one copy of each control onto the form.
  6. Right click on the data control and select ADODC Properties from the pop-up menu
  7. Click Build to bring up the connection string builder.
  8. Select Pervasive OLE DB Provider from the list and click Next.
  9. Enter a DBNames entry or a pathname for the Data Source
  10. Click OK.
  11. Click the RecordSource tab of the ADODC Properties dialog.
  12. Change the command type to adCmdTable using the drop-down list.
  13. Enter a table name or select one from the drop-down list and click OK.
  14. Select the grid, and edit the properties using F4.
  15. Change the Data Source property to adodc1 using the drop down list.
  16. Run the application.

Chapter contents
Publication contents

Prev topic: ADO/OLE DB Reference Information
Next topic: Creating a Connection