用户操作
[即时聊天] [发私信] [加为好友]
曹瑞宇ID:cashcho
19759次访问,排名6302,好友0人,关注者0人。
cashcho的文章
原创 18 篇
翻译 0 篇
转载 0 篇
评论 6 篇
最近评论
lshvs2005:好,谢谢。 写得详细
limit:3x~~! 受益非浅,唯一的遗憾是没有更新了~!
想必是学有所成太忙没时间照顾这里了!3q again!
会吃草的牛:你的确是个理想主义者
夜未央:牛!兼职写写剧本什么的
max:学习,不错,不错!!
文章分类
收藏
    相册
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 在 Visual Studio .NET中使用Crystal Report(下)收藏

    新一篇: .NET是什么,如何影响我? | 旧一篇: 在 Visual Studio .NET中使用Crystal Report(上)




    Visual Studio .NET中使用Crystal Report()




     




    from www.aspfree.com
    translated by cash(天下第七)
    cashcao@msn.com




     




    Crystal Report 演示-使用Push Model




     




    下面看看如何使用Push Model实现Crystal Reports




     




    1.创建一个设计时的dataset




    2.创建一个.rpt文件并指向我们前面创建的dataset




    3..aspx页面上放置Crystal Report Viewer控件,设定它的属性指向上一步创建的.rpt文件。




    4.code behind page中,书写连接数据库的函数




    5. 加上databind方法。 




     




    创建一个设计时的dataset去定义ReportsFielsds.




     




    1)"Solution Explorer"右击,选择"Add" --> select "Add New Item--> Select "DataSet"




     










     




    2) "Server Explorer"面板中的"SQL Server"拖进"Stores"




     










     




    3) 这将在dataset中创建一个"Stores" table




     




     










     




    用这种方法创建的.xsd文件仅仅包含了field的定义,里面没有任何数据。需要你创建一个与数据库的链接并且将数据填充进去。




     




    创建.rpt文件




     




    4)创建一个.rpt文件。与前面唯一不同的是不通过Crystal Report得到表,我们将用dataset来创建它。




     




    5)建立.rpt文件后,右击"Details" section,选择"Add/Remove Database"




     




    6) "Database Expert"窗口,展开"Project Data",展开"ADO.NET DataSet","DataSet1", 选择 "Stores" table.




     




    7)点击">""Stores" table包括进"Selected Tables" 




     










     




    8) 接下来设定report的布局。




     




    创建一个Crystal Report Viewer Control




     




    9)  接下来的步骤是用PULL Model创建一个Crystal Report viewer Control并设定它的属性。




     




    code behind page 代码:




     




    10)为你的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 our DataSet created at Design Time      




     




            MyDA.Fill(myDS, "Stores")  




     




            'You have to use the same name as that of your Dataset that you created during design time




      




            Dim oRpt As New CrystalReport1()




             ' This is the Crystal Report file created at Design Time




      




            oRpt.SetDataSource(myDS)




             ' Set the SetDataSource property of the Report to the Dataset




     




            CrystalReportViewer1.ReportSource = oRpt




             ' Set the Crystal Report Viewer's property to the oRpt Report object that we created




      




        End Sub




     




    注意:在上面的代码中,你可能会注意到oRpt对象是"Strongly Typed" Report file的一个实例。 如果我们用"UnTyped" Report,我们将不得不使用ReportDocument 对象并且手工load这个report文件进去。




     




    运行你的程序




     




    11) F5 运行。




     




    输出report文件到另一种格式




     




    你可以选择将你的report文件输出成以下格式:




     




    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)




     




    事实上,你可以放置一个button来引发一个输出函数。




     




    输出一个以Pull Model创建的report文件




     




    当输出一个以Pull Model创建的report文件的时候,Crystal Report对与数据库的连接及所需的记录很敏感,所以你只可使用下面提供的代码:




     




    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 Report file here.




     




            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 report to other sources




             ' like Microsoft Exchange, MAPI, etc.       




     




            myReport.ExportOptions.ExportFormatType = CrystalDecisions. [Shared].ExportFormatType.PortableDocFormat




          'Here we are exporting the report to a .pdf format.  You can




            ' also choose any of the other formats specified above.




     




            DiskOpts.DiskFileName = "c:\Output.pdf"




            'If you do not specify the exact path here (i.e. including




            ' the drive and Directory),




            'then you would find your output file landing up in the




            'c:\WinNT\System32 directory - atleast in case of a




            ' Windows 2000 System




     




            myReport.ExportOptions.DestinationOptions = DiskOpts




          'The Reports Export Options does not have a filename property




            'that can be directly set. Instead, you will have to use




            'the DiskFileDestinationOptions object and set its DiskFileName




            'property to the file name (including the path) of your  choice.




            'Then you would set the Report Export Options




            'DestinationOptions property to point to the




            'DiskFileDestinationOption object. 




     




            myReport.Export()




            'This statement exports the report based on the previously set properties.




     




    End Sub




     




    输出一个由Push Model创建的report文件




     




    当输出一个由Push Model创建的report文件时,第一步是必需手工创建一个连接并绑定数据库。设定这个reports‘SetDataSource’为此dataset(如前所述)。然后就可以调用上面所示的代码了。




    _______________________________________________________________________________




     




    提交者:




    Ajay Varghese & Shankar N.S.




    Sr. Software Engineers,




    Jarvis Infotech 

    发表于 @ 2002年02月05日 10:49:00|评论(loading...)|编辑

    新一篇: .NET是什么,如何影响我? | 旧一篇: 在 Visual Studio .NET中使用Crystal Report(上)

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © cashcho