Use the PUSH mode
We use the following steps to perform crystal reports using the PUSH mode:
Design a DataSet
2. Create a .rpt file simultaneously assign it to the DataSet established in the previous step.
3. Drag and drop a CrystalReportViewer control in the ASPX page to connect to the previous RPT file.
4. Access the database in your code and save the data into DataSet
5. Call the DataBind method.
Design a DataSet
1) Right-click "Solution Browser", select "Add" - "Add New Item" -> "Data Set"
2) Drag and drop the "Stores" table in "SQL Server" in Server Explorer ".
3) There will be a structural diagram of a Stores table in the data set.
--. only contains a structural diagram in .xsd file, there will be no data in it.
Create a .rpt file:
4) Creating this file using the methods described above, the only difference is to use the data set to replace the front direct connection data.
5) After establishing the .rpt file, right click on "Details" -> Add / Remove Database.
6) In the Database Expert window, expand "Project Data" (instead of previous OLEDB), expand "ADO.NET Dataset" - "Dataset1", select "Stores" table.
7) Add "Stores" table to "Selected Table", click "OK"
8) Create a WebForm using the method in PULL mode
Create a Crystal Report Viewer control
9) Establish a Crystal Report Viewer control and set its properties, which is consistent with the PULL mode.
Code Behind code:
10) Use the subunies below in the Page_Load method:
VB.NET code:
Sub BindReport () Dim myConnection As New SqlClient.SqlConnection () myConnection.ConnectionString = "server = (local) / NetSDK; database = pubs; Trusted_Connection = yes" Dim MyCommand As New SqlClient.SqlCommand () MyCommand.Connection = myConnection MyCommand. CommandText = "Select * from Stores" MyCommand.CommandType = CommandType.Text Dim MyDA As New SqlClient.SqlDataAdapter () MyDA.SelectCommand = MyCommand Dim myDS As New Dataset1 () 'this is the DataSet MyDA.Fill we use in the design mode (MYDS, "Stores") 'You have to use the same name as you front DataSet. Dim ORPT AS New CrystalReport1 () 'Crystal Report Bind ORPT.SetDataSource (MYDS)' Setting the crystal report ReportSource CrystalReportViewer1.Reportsource = ORPT End Sub
C # code:
private void BindReport () {string strProvider = "Server = (local); DataBase = pubs; UID = sa; PWD ="; CrystalReport1 oCR = new CrystalReport1 (); Dataset1 ds = new Dataset1 (); 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 have to pay attention to the ORPT is a "strongly type" 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 report files into other formats
You can export report files into the following format:
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 reports using a PULL mode
When the file using the PULL mode is exported, the crystal report accurately opens the required data, the following is the code to perform 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 report the crystal to establish a strong-typed example is . 'This option is required also exported into other files' are as Microsoft Exchange, MAPI like Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions () myReport.ExportOptions.ExportDestinationType = CrystalDecisions. [Shared] .ExportDestinationType.DiskFile. myReport.ExportOptions.ExportFormatType = CrystalDecisions [Shared] .ExportFormatType.PortableDocFormat. 'here we exported into .pdf file format, you can also choose other types of files above DiskOpts.DiskFileName = "c: /Output.pdf"' If you do not Specify the exact directory, then the file will be saved to the [Windows] / System32 directory to go to myReport.ExportOptions.DestinationOptions = Diskopts 'crystal report file does not contain a direct filename property, so you can't specify the saved file name' so you Have to use the DiskFileDestinationOptionOptions object, set its diskfilename properties 'for the path you want, and finally specify the DestinationSoptions property of the crystal report to the code above the code ()' will complete the export work. End Sub Use a PUSH mode to export crystal reports
When the exported report is established by the PUSH mode, the first step is to establish a connection and assemble the DataSet, set the setDataSource attribute of the report. Then there is a PULL mode in the steps below.