ComponentOne Query 8.0
Tutorial 3 - Query Result Fields in C1QueryFrame Control

In this tutorial, you will learn how to attach two C1QueryFrame controls to a C1Query control. One of them manages filter conditions, the other – result fields, with optional sort and aggregation function. Complete the following steps:

  1. Start a new project.

  2. Place the following controls on the form as shown in the figure: a C1Query control (C1Query1), two C1QueryFrame control (C1QueryFrame1,2), a TabStrip control (add reference to Microsoft Windows Common Controls to the project), Microsoft ADODC control (Adodc1), a Microsoft DataGrid control (DataGrid1) and two command buttons (Command1,2).

  3. Set C1QueryFrame1 control SchemaControl property to C1Query1 and the ContentsType property to 2 – c1qResultFields.

    Set C1QueryFrame2 control SchemaControl property to C1Query1 and the ContentsType property to 2 – 2 – c1qConditions.

    Set Adodc1 control ConnectionString to Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb;Persist Security Info=False

  4. Specify the schema for C1Query1, repeating steps 3-8 of Tutorial 2 - Using C1Query Schema Designer.

  5. Add the following code managing visibility of the C1QueryFrame controls on TabStrip1:

    Example Title
    Copy Code
    Private Sub Form_Load()
    
       C1QueryFrame1.Visible = True
    
       C1QueryFrame2.Visible = False
    
    End Sub
    
     
    
    Private Sub TabStrip1_Click()
    
       C1QueryFrame1.Visible = TabStrip1.SelectedItem.Index = 1
    
       C1QueryFrame2.Visible = TabStrip1.SelectedItem.Index = 2
    
    End Sub
    
  6. Add the following code to the buttons’ Click event:

    Example Title
    Copy Code
    Private Sub Command1_Click()
    
       OK = C1Query1.BuildSQL
    
       If OK Then
    
          Adodc1.CommandType = adCmdText
    
          Adodc1.RecordSource = C1Query1.SQL
    
          Adodc1.Refresh
    
          Set DataGrid1.DataSource = Adodc1
    
        End If
    
    End Sub
    
     
    
    Private Sub Command2_Click()
    
       C1Query1.BuildSQL
    
       MsgBox C1Query1.SQL
    
    End Sub
    

Run the Program and Observe the Following:

Now you can specify conditions in the Conditions tab, and result fields in the Fields tab. The C1QueryFrame1 control with ContentsType = 2 – c1qResultFields allows the user to specify result fields and, for each field, optional sort and aggregation function.

 

 


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

Product Support Forum  |  Documentation Feedback