In the process of using VB comes with the report, I have encountered problems with the dynamic packet report. Generally, you should use a packet report to create a DataEnvironment in VB and establish a database coupling and command object, set a packet field in the command object, and finally add these packet fields to the report. However, this method can only adapt to static data sources. This method is powerless when the fields in the data table are not fixed, or when the data table cannot be pre-known. After viewing various information, we can find packet information by using Data Shaping. Let's introduce how to dynamically create group information and apply it to the VB report.
To use Data Shaping, the program must use ActiveX Data Object (ADO) to connect to the database, the key to solve the problem is to use the Data Shaping driver instead of the typically used OLE DB driver, its usage is similar to other drivers, For existing data access code, it is not used as any modification, just a simple modification of the connection code to support Data Shaping. The specific practices are as follows:
Connect the connection parameters
Provider is set to "msdatashape"
Connectionstring = "provider = msdatashape; Data Provider = usual driver; data source = ...; other parameters"
Then, data connection can be performed in peacetime, and various data is operated. Such connected data has exported all features with ordinary methods, while having the upcoming Data Shaping feature, you can build your own group information:
Write the SQL statement used to open the record set as follows:
Shape {SELECT field 1, field 2, field 3, ..., field n from existing table} AS new name 1
Compute New Name 1 AS New Name 2 BY Packet Field 1, Group Field 2, ...
In the above statement, it is necessary to note that the group field must appear in Select, otherwise it will be an error. The recordset that is opened with this SQL statement contains several fields, which are: new names 2, packet field 1-n. When using, the open recording set RS is used as the DataSource of the report, and the packet field 1-N and various statistical functions can be used in the report, and the fields should be used in the body. The DataMenber set to the edit box is "new name
2"
Please refer to the following statement for details.
MyReport.sections ("GROUPHEADER"). Controls ("Text1"). DataField = "Packet field
1"
MyReport.sections ("Groupfooter"). Controls ("Function1"). DataMember = "New Name 2"
MyReport.sections ("Groupfooter"). Controls ("Function1"). DataField = "Field 1"
MyReport.sections ("pagecontent"). Controls ("text2"). DataMember = "New Name 2"
MyReport.sections ("pagecontent"). Controls ("text2"). Datafield = field
1"
The above-mentioned reports can be bound to dynamic data, which is very useful for those operating temporary tables because the temporary table is unable to design packets with designer. About Data Shaping Details You can refer to MSDN online resources. In general, we can design a similar structure with designers, then view the code generated by the VB designer, so you can use our own table.