Data Reporting is a report, which can easily generate a complex report by dragging and dropping the fields of the ENVIRONMENT. However, sometimes it is more necessary to connect the Data Report (DataReport) to an ActiveX Data Object (ADO) recordset instead of a data environment. For example, may have generated a layered query with ADO, or may have an N layer application for acquiring records in things in things.
So how can I directly bind the ADO record q RS to Data Report? Please see the details below.
Description:
First, use the data environment to generate a layered query, then generate a simple data report (DataReport) on the basis of your query and bind it to the data environment.
Use the data environment to bind the NWIND database (Visual Basic's own sample database), including the following steps:
Create a new standard EXE project with VB.
Add a data environment to the project and rename it as DecustomerRDERS.
Rename the initial connection to CNNWind.
Set the connection to use the OLE database tool for Microsoft.jet.OleDb.3.51.
Locate the NWIND database on your machine.
Add a command to this connection and rename it as a user (Customers).
Set the user command to query the user table.
Add a subcommand to the user command and name it as an order (Orders).
Set the order command to query the order table.
Use the CustomerID field to associate these two commands in the relational table.
Add a data report to the project and rename RPTCUSTOMERORDERS.
Set the DataSource property of the Data Report to DecustomerORDERS.
Set the DataMember property of the DataReport to the user.
Right click on DataReport to clear "Show Report Header / Footer".
Right click on DataReport and clear "show page header / footer".
Right-click DataReport and select "Insert Group Header / Footer".
Drag the user code (Customerid) and company name field from the Customers command from the data environment to the Group HEADER section.
Drag the order code (OrderID) and OrderDate fields to the Detail section from the ORDERIS command from the data environment.
Add a command button (Commandbutton) on the form.
Then add the following code on your form:
Private submmand1_click ()
RPTCustomerRorders.show
End Sub
Run this project, click CommandButton, you should see a report with users and order information.
In order to bind the Data Report (DataReport) to the hierarchical recordset generated by the data environment, add the following code:
Private sub flow_load ()
DIM INTCTRL AS INTEGER
With rptcustomerorders
SET.DataSource = Nothing
.DataMember = ""
Set.DataSource = Decustomerorders.rscustomers
WITH.SECTIONS ("Section2"). Controls
For intctrl = 1 to.count
If TypeOf.Item (intctrl) is rpttextbox OR_
TypeOf.Item (IntCtrl) is rptfunction then
.Item (intctrl) .DataMember = ""
END IF
Next Intctrl
End with
Note: If you miss the 13th and step 14, you need to change "Section 2" to "Section 6" in the above code.
Conclusion: Running this project will see reports of users and order information.
Data Reports Use the DataSource and DataMEmber properties to find the top-level command for the establishment report. For example, if there is a hierarchy containing the user, orders and order details information in the data environment, you only want to display orders and order details, then you should set the DataSource property to the data environment and set the DataMber property to Order command.
There are two attributes in each field in the DataReport, so that the data environment can determine what information displayed in the report:
DataMember
Datafield
You can choose the layer that includes information you want to display using the DataMember property. Use the DataField property to select the field you want to display.
For example, the user code field has in the user table and the order table. If you want to display the user code field and user information, set the DataMmbER property to Customers. And if you want to display the user code and order information, you should set the DataMmbER property to an empty string.
When you are binding the Data Report (DataReport) as in step 21, you should set the DataSource property of the Data Report to record the set object, and set the DataMember property to an empty string. For fields in the report, the DataMember property of the top-level record set (in this example is user information) should be set to a null string. For additional information in the top recording set (in this example, order information), the DataMber property of the text box control of the report should be set to the name of the command (in this case as Orders).
When you are running, you can solve the records in the ADO record object RS to the data report, I hope to use it! ! !