In Visual Studio. NET use Crystal (bottom) (cashcho translation)

Source: Internet
Author: User
Tags visual studio
Visual in the Visual Studio. NET used in Crystal ( under )







From www.aspfree.com
Translated by Cash (world seventh)
Cashcao@msn.com (cashcao@msn.com)







Crystal Demo-Use Push 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-time DataSet to define Reports of the Fielsds.







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 . Rpt file







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 a Crystal the Viewer control







9 The next step is to create a crystal with the pull model and set its properties.







Change code behind page Code:







10 The following program is designed for your page load:







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 my DataSet created at







Myda.fill (myDS, "Stores")







' 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 the file 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 to Pull Model created by the file







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 ()











MyReport.ExportOptions.ExportDestinationType = CrystalDecisions. [Shared]. Exportdestinationtype.diskfile



' You also have the option to export the "to" sources



' Like Microsoft Exchange, MAPI, etc.







MyReport.ExportOptions.ExportFormatType = CrystalDecisions. [Shared]. Exportformattype.portabledocformat



' Here we are exporting the ' A. pdf format. You can



' Also choose of the other formats specified above.







Diskopts.diskfilename = "C:\Output.pdf"



' If you don't specify the exact path here (i.e. including



' The drive and Directory,



' Then you would find your output file landing up



' C:\WinNT\System32 Directory-atleast in the case of a



' Windows System







MyReport.ExportOptions.DestinationOptions = diskopts



' 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 by Push Model created by the file







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.




Related Article

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.