VB and reports (III. Data Connection and code implementation)

Source: Internet
Author: User

VB and reports (III. Data Connection andCodeImplementation)

When a report template is created almost,Data connection should be established.,Data Connection procedure:

Note that step 7 is required.,If the password cannot be saved,The following error occurs when the query statement is written and then tested.;

This is to ensure data security,The password written in step 1 is only allowed once.,When the database is connected again, the connection will fail if the user name and password are not entered.,So step 7 is necessary..


Then execute the data title generation,Execute Edit to generate table columns Based on fields.

Generate as shown in the right figure

You can drag and drop to adjust the column width..You can also adjust some other attributes through the attribute bar on the right..

So far, the database has been connected successfully.

Next, the code is implemented..Before implementing the following code, add components and references.,Then add the report Control.

The Code is as follows:

 Option explicit defines the report object dim report as grprolibctl. gridppreport private sub form_load () dim strsql as string dim strmsg as string strsql = "select * From jiezhang_info where date = '" & Date & "'" 'instantiate the report set report = new grprolibctl. gridppreport' loads the template report. loadfromfile (App. path & "\ dayaccount. GRF ") 'Data source connection report. detailgrid. recordset. connectionstring = connectstring 'use the SELECT query to create a record set report. detailgrid. recordset. querysql = strsql' View Report grdisplayviewer1.report = Report grdisplayviewer1.start end sub private sub cmdrefresh_click () report. detailgrid. recordset. querysql = "select * From jiezhang_info where date = '" & Date & "'" grdisplayviewer1.refresh 'refresh end sub private sub into view_click () report. printpreview (true) 'print and preview end sub private sub into print_click () report. [print] (true) 'print end sub 

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.