Asp.net| Crystal Report using push mode
We used the following steps to execute the Crystal report using push mode:
1. Design a DataSet
2. Create a. rpt file and assign it to the dataset that was established in the previous step.
3. Drag and drop a Crystalreportviewer control in the ASPX page and connect it to the previous RPT file.
4. Access the database in code and save the data in a dataset
5. Call the DataBind method.
Design a DataSet
1) Right-click Solution Explorer and select Add--Add New Item--> DataSet
2 drag and drop the Stores table from SQL Server in Server Explorer (located in the pubs database).
3 There will be a chart of the stores table in the dataset at this time.
-The. xsd file contains only one structure diagram, but no data is in it.
To create a. rpt file:
4 Use the method described above to create this file, the only difference is to use the dataset to replace the previous direct connection data.
5 after creating the. rpt file, right-click the "Details"--> "Add/Remove Database"
6 in the Database Experts window, expand project data (instead of previous OLE DB), and expand ADO. NET DataSet "--" DataSet1 ", select the" Stores "table.
7 Add the "Stores" table to the selected table and click OK
8 using the method of Pull mode to establish a WebForm
Create a Crystal the Viewer control
9 Create a crystal and set its properties, which is consistent with the pull mode.
Code behind codes:
10 Use the following child function in the Page_Load method:
Vb. NET code:
Sub Bindreport ()
Dim MyConnection as New sqlclient.sqlconnection ()
SqlConnection myconn = new SqlConnection (strprovider);
MyConn.Open ();
String Strsel = "SELECT * from Stores";
SqlDataAdapter myadapter = new SqlDataAdapter (Strsel,myconn);
Myadapter.fill (ds, "stores");
Ocr.setdatasource (DS);
This. Crystalreportviewer1.reportsource = OCR;
}
Note: In the above code, you should pay attention to the ORPT is the "strongly Typed" report file. If you need to use the "untyped" report, you have to use the Reportdocument object and then call the report file.
Run your program.
11. Run your Program
Export a report file to another format
You can export a report file to the following format:
1. PDF (Portable Document Format)
2. DOC (MS Word Document)
3. XLS (MS Excel spreadsheet)
4. HTML (Hyper Text Markup language–3.2 or 4.0 compliant)
5. RTF (Rich Text Format)
Export a report using pull mode
When exporting a file created using the pull mode, the Crystal Report accurately opens the required data, and the following is the code that performs the export function:
C # code:
Vb. NET code:
Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
Dim Myreport as CrystalReport1 = New CrystalReport1 ()
' Note: Here we build an example of a strong-typed Crystal report.
Dim diskopts as CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions ()
' The Crystal Report file does not contain a direct filename attribute, so you cannot specify the saved file name directly
' So you have to use the Diskfiledestinationoptions object to set its diskfilename properties
' For the path you want, the final destinationsoptions attribute of the Crystal Report is specified as above diskfiledestinationoption
Myreport.export ()
' The code above will complete the export work.
End Sub
Export Crystal Reports using push mode
When the exported report is created by the push mode, the first step is to programmatically build the connection and assemble the dataset to set the Setdatasource property of the report. The following steps will have the same pull mode.
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.