Step 1: I don't need to teach you how to add a form! Drag the crystalreportviewer control in the toolbox to the form,
Step 2: Right-click to add a new item and find the dataset dataset1.xsd.
Step 3: add the new Crystal Report crystalreport1.rpt and select a blank report.
Step 4: Right-click dataset1.xsd and choose "Add-tableadapter" to name it: you define "dscardconsumption", connect to the database as prompted, and then write SQL statements.
This dataset is complete.
Step 5: Double-click crystalreport1.rpt to go to the upper left corner and find --- field resource manager -- database Field
Right-click-database field-Database Expert-a dialog box is displayed, and select project data-ADO. Net dataset.
Click it to find the dataset "dscardconsumption" you just completed, and then click OK.
Then -- there is an extra dataset under the database field, that is, there are many fields in dscardconsumption, and then drag it to crystalreport1.rpt
The details are arranged horizontally and sequentially. The upper and lower fields will appear when you place the information. The following fields show the database data and the above fields show the title. This is done.
Step 6: lower in the formCode:
// This is the dateset returned by the query method.
Dataset = reportbll. getquerycardconsumption (START, finish, cardno );
// This is the name of the bound dataset "cardconsumption"
Dataset. Tables [0]. tablename = "cardconsumption ";
// This is the name of crystalreport1.rpt created in step 5.
Rptcardconsumption Cr = new rptcardconsumption ();
Cr. setdatasource (Dataset );
Crvcardconsumption. reportsource = CR;