Tutorials - True DataControl > Tutorial 16 - Query Mode (part 2) |
This tutorial is the second part of the lesson begun in Tutorial 15. It demonstrates another option that you have with True DataControl Query Mode: you will create a TData control and data-bound controls intended solely for entering queries. Query results will be displayed with a separate TData control in a separate DataGrid.
Start a new project.
Place the following controls on the form (Form1) as shown in the figure: two TData controls (TData1, TData2), a DataGrid control (DataGrid1), seven TextBox controls (Text1 to 7), seven labels (Label1 to 7) and a button (Command1).
Set properties as follows (you can use the DataSource property page to set TData data source properties, as described in Tutorial 2):
Example Title |
Copy Code
|
---|---|
TData1.ConnectionString Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Program Files\ComponentOne Studio\Common\TDDEMO.MDB TData1.CommandType 2 – adCmdTable TData1.RecordSource Orders TData1.QueryMode True TData1.EOFAction adDoAddNew TData2.ConnectionString Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Program Files\ComponentOne Studio\Common\TDDEMO.MDB TData2.CommandType 2 – adCmdTable TData2.RecordSource Orders TData2.QueryMode False DataGrid1.DataSource TData2 |
Open the True DataControl property pages for TData1, and go to the Fields page. Delete all fields except the following: OrderID, CustomerID, ShipName (to delete a field, select it in the field list and press Del).
In the Fields property page for TData1, select the ShipName field and change its QueryOperation property, select starts with in the Query Operation combo box.
In the Fields property page for TData1, create four additional fields (by clicking the right mouse button and choosing New Field from the menu). For each of them select the data radio button, indicating that the field is a data field. For each of the four new fields, set its Name, DataSourceField and QueryOperation properties, typing in the Name edit box and selecting from the lists in the DataSource Field and Query Operationcombo boxes.
Note: You must change Query Mode to 0 - Both or 1 - Query only for the Query Operation combo box to become available. |
Name: |
DataSource Field: |
Query Operation: |
OrderDateFrom |
OrderDate |
>= |
OrderDateTo |
OrderDate |
<= |
RequiredDateFrom |
RequiredDate |
>= |
RequiredDateTo |
RequiredDate |
<= |
Set properties of other controls as follows:
Text1.DataSource |
TData1 |
Text1.DataField |
OrderID |
Text2.DataSource |
TData1 |
Text2.DataField |
CustomerID |
Text3.DataSource |
TData1 |
Text3.DataField |
OrderDateFrom |
Text4.DataSource |
TData1 |
Text4.DataField |
OrderDateTo |
Text5.DataSource |
TData1 |
Text5.DataField |
ShipName |
Text6.DataSource |
TData1 |
Text6.DataField |
RequiredDateFrom |
Text7.DataSource |
TData1 |
Text7.DataField |
RequiredDateTo |
Set label and button captions according to the picture.
Add the following code to Command1:
Example Title |
Copy Code
|
---|---|
Private Sub Command1_Click() TData2.SourceRecordset.Filter = TData1.QueryFilter End Sub |
We leave it to you to experiment with different queries and their results, as it was done in Tutorial 15. We just want you to notice the following:
Now you have a sophisticated query form where you can specify different criteria, including date ranges. Four new fields created on Step 5 support data range conditions. ShipName condition is "starts with" rather than "equals," that was specified on Step 4. Field values in a record generate conditions joined with AND.
You can specify complex queries with more than one condition joined with OR, simply by adding new records to the query form. To add a new record to query, simply pressing the Next button on TData1 when it is positioned on the last record. This is enabled by our setting TData1.EOFAction=adDoAddNew.
Pressing the Apply button applies the specified query to TData2. TData1 remains in query mode at all times.
Congratulations, you have completed all sixteen True DataControl tutorials! You are now ready to take full advantage of True DataControl in your applications.