Visual
in theVisual Studio. NETused inCrystal (under)
From www.aspfree.com
Translated by Cash (world seventh)
Cashcao@msn.com (cashcao@msn.com)
CrystalDemo-UsePush Model
Let's see how to implement Crystal Reports using push model
1. Create a design-time dataset
2. Create a. rpt file and point to the dataset we created earlier
3. Place the crystal on the. aspx page control, setting its properties to the. rpt file created in the previous step.
4. In code behind page, write a function that connects to a database
5. Add the DataBind method.
Create a design-timeDataSetto defineReportsof theFielsds.
1 in the "Solution Explorer" right click, select "Add"--> Select "Add New item--> Select DataSet"
2 Drag the "Stores" table from SQL Server in the server Explorer panel
3 This will create a "Stores" table in the DataSet
The. xsd file created in this way contains only the definition of field, with no data in it. You need to create a link to the database and populate it with data.
Create. Rptfile
4 Create a. rpt file. The only difference with the previous one is that the table is not obtained through the crystal, and we will use the dataset to create it.
5 after the establishment of the. rpt file, right click "Details" section, select "Add/remove Database"
6 in the Database Expert window, expand Project Data, expand the Ado.net DataSet, DataSet1, and select Stores table.
7 Click ">" to include "Stores" table in "Selected Tables"
8 Next set the layout of the bill.
Create aCrystal the Viewer control
9 The next step is to create a crystal with the pull model and set its properties.
Changecode behind pageCode:
10 The following program is designed for your page load:
Sub Bindreport ()
Dim MyConnection as New sqlclient.sqlconnection ()
' You are have to use the same name as this of your Dataset that you created during
Dim orpt as New CrystalReport1 ()
' This is the Crystal-file created at
Orpt.setdatasource (myDS)
' Set the Setdatasource property of the ' the ' the ' the ' Dataset
Crystalreportviewer1.reportsource = Orpt
' Set the Crystal the Viewer ' s property to the Orpt, ' we created
End Sub
Note: In the above code, you may notice that the Orpt object is an instance of the "strongly Typed" file. If we use the "untyped", we will have to use the Reportdocument object and manually load this file in.
to run your program
One) F5 run.
Output thefile to a different format
You can choose to output your file in 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)
In fact, you can put a button to throw an output function.
output one toPull Modelcreated by thefile
When outputting a reporting file created in pull model, the Crystal reporting is sensitive to the connection to the database and the required records, so you can only use the code provided below:
Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
Dim Myreport as CrystalReport1 = New CrystalReport1 ()
' Note:we are creating an instance of the strongly-typed Crystal.
Dim diskopts as CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions ()
' The Reports Export Options does not have a filename
' can be directly set. Instead, you'll have to use
' The Diskfiledestinationoptions object and set its diskfilename
' property to ' file name (including the path) of your choice.
' Then you would set the
' Destinationoptions to the '
' Diskfiledestinationoption object.
Myreport.export ()
' This statement exports the "based on the previously set properties.
End Sub
output one byPush Modelcreated by thefile
When you output a file that is created by push model, the first step is to manually create a connection and bind the database. Set this reports ' Setdatasource ' for this dataset (as described earlier). You can then invoke the code shown above.
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.