ComponentOne List 8.0 for ActiveX
Tutorial 5 - Using True DBList with SQL Query Results

An important feature of True DBList is its ability to automatically sense changes to the database at run time. In this tutorial, you will learn how to use True DBList to display the results of ad-hoc SQL queries. Note that no code is necessary to tell the list what to do---the list will automatically change its field layout to match the new configuration of the query result. Also note that in order for the list to automatically respond to field layout changes, you must not have defined any column properties at design time. If a layout is already defined, use the list's Clear Fields context menu command to remove it.This will allow the list to configure itself automatically.

  1. Start a new project.

  2. Place a Data control (Data1), a True DBList control (TDBList1), a command button (Command1), and a TextBox control (Text1) on the form (Form1) as shown in this figure.

  3. Set the DatabaseName (Data control) property of Data1 to TDBLDemo.mdb, and the RecordSource (Data control) property to Customer.

  4. Set the RowSource property of TDBList1 to Data1.

  5. Set the Caption property of Command1 to Execute SQL and the MultiLine (TextBox control) property of Text1 to True.  Set the Text (TextBox control) property to Enter SQL statement here.

  6. Add the following code to Command1:

    Example Title
    Copy Code
    Private Sub Command1_Click()
    
     
    
    ' Execute the SQL statement in Text1, and trigger an error
    
    ' message if something goes wrong.
    
        On Error GoTo SQLErr
    
        Data1.RecordSource = Text1.Text
    
        Data1.Refresh
    
        TDBList1.SetFocus
    
        Exit Sub
    
     
    
    SQLErr:
    
        MsgBox "Error Executing SQL Statement"
    
        Exit Sub
    
    End Sub
    

Run the program and observe the following:

To end the program, press the End button on the Visual Basic toolbar. You have successfully completed Tutorial 5.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback