Talking about the call of Crystal Reports in VB

Source: Internet
Author: User
Tags join client
Environment: Vb6.0,crystal Reports 9.0
Crystal Reports is used in a project to summarize some experiences and lessons learned.
Take a set of documents as an example.
The document includes the document header and the document body. The document header and the document body may be a one-to-many relationship. And they exist in two tables respectively, with the field FID to do the association. Requires the ability to dynamically pass the parameter fid, showing different results.
First of all, open Crystal Reports, do a document template rpt. There are a number of ways to make a report, such as creating a connection between tables directly with its graphical tool, and then holding the fields you want to display into the report, or calling a stored procedure that has already been written, or directly editing the command. Then put the fields you want to display into the report. However, often the problem comes out here, using a graphical tool to produce a report, in VB when the report passed to the datasource, often because the field does not correspond, and caused some of the data can not be displayed. Therefore, it is recommended to use command to edit the SQL statements in Crystal Reports to make the documents. This SQL statement is then copy into the VB code, generating a new result set and assigning the new data source to the RPT file. This guarantees the correspondence of each field.
Assuming that the document header information is stored in the table quotation, the document body is stored in the table Quotationentry. The document header information needs to display the field customer name Fcustomer, the document number Fbillno, the document date Fbilldate, the system single Fbiller ... The document body needs to display the merchandise detail, including the commodity code Fnumber, the commodity style fstyle, the commodity size fsize, the commodity color fcolor ... The two Table association fields are FID.
Then, in the command of the RPT file, add the SQL statement "select a.*,b.* from quotation a LEFT join Quotationentry B on A.fid=b.fid". Then pull the required fields into the report.
In VB, first apply Crystal Reports 9 ActionX designer disign and Runtime Library, and add parts crystal the viewer control 9.
In the form, add the part you just added. You can call and display the.

Public billid As Integer ' incoming parameters
Private Sub Command1_Click ()
Dim Capp as New CRAXDDRT. Application
Dim carp as New craxddrt. The
Dim Conn as New Connection
Dim rs as New Recordset
Dim SQL as String
Conn. ConnectionString = "Provider=SQLOLEDB.1; Password=sa; Persist Security info=true; User id=sa;initial catalog=ais20041209121508;data source=127.0.0.1 "
sql = "Select a.*,b.* from quotation a LEFT join Quotationentry B on A.fid=b.fid where a.fid=" &billid
With Conn
. Open
Rs. Open SQL, Conn, adOpenStatic, adLockBatchOptimistic
End With
Set carp = Capp. OpenReport ("E:\Code\Component\Client\Quotation.rpt")
Carp. Discardsaveddata ' Empty previous data
Carp. Database.setdatasource RS
Crviewer91.reportsource = Carp
Crviewer91.viewreport
End Sub
Also can be written quotation.rpt file together into VB, the specific way is in the VB Project right key load Crystal Report 9 Designer, choose to open with some files, open E:\Code\Component\Client\ Quotation.rpt, and loaded into it. The above code set carp = Capp. OpenReport ("E:\Code\Component\Client\Quotation.rpt") is not available, replace the carp directly with the name of the control that is loaded in.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.