在 Visual Studio .NET中使用Crystal Report(下)
2008-04-24 14:23
417 查看
在 Visual Studio .NET中使用Crystal Report(下)
from www.aspfree.com
translated by cash(天下第七)
cashcao@msn.com
Crystal Report [/b]演示-使用[/b]Push Model[/b]
下面看看如何使用Push Model实现Crystal Reports
1.创建一个设计时的dataset
2.创建一个.rpt文件并指向我们前面创建的dataset
3.在.aspx页面上放置Crystal Report Viewer控件,设定它的属性指向上一步创建的.rpt文件。
4.在code behind page中,书写连接数据库的函数
5. 加上databind方法。
创建一个设计时的dataset去定义Reports的Fielsds.
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 运行。
输出[/b]Report[/b]文件到另一种格式[/b]
[/b]
你可以选择将你的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来引发一个输出函数。
输出一个以[/b]Pull Model[/b]创建的[/b]Report[/b]文件[/b]
[/b]
当输出一个以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()
from www.aspfree.com
translated by cash(天下第七)
cashcao@msn.com
Crystal Report [/b]演示-使用[/b]Push Model[/b]
下面看看如何使用Push Model实现Crystal Reports
1.创建一个设计时的dataset
2.创建一个.rpt文件并指向我们前面创建的dataset
3.在.aspx页面上放置Crystal Report Viewer控件,设定它的属性指向上一步创建的.rpt文件。
4.在code behind page中,书写连接数据库的函数
5. 加上databind方法。
创建一个设计时的dataset去定义Reports的Fielsds.
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 运行。
输出[/b]Report[/b]文件到另一种格式[/b]
[/b]
你可以选择将你的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来引发一个输出函数。
输出一个以[/b]Pull Model[/b]创建的[/b]Report[/b]文件[/b]
[/b]
当输出一个以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()
相关文章推荐
- 在 Visual Studio .NET中使用Crystal Report(中)
- 在Visual Studio.NET中使用Crystal Report
- 在 Visual Studio .NET中使用Crystal Report(下)
- 在 Visual Studio .NET中使用Crystal Report(上)
- 在 Visual Studio .NET中使用Crystal Report(上)
- 在 Visual Studio .NET中使用Crystal Report(上)
- 在 Visual Studio .NET中使用Crystal Report(中)
- 在 Visual Studio .NET中使用Crystal Report
- 在Visual Studio.NET中使用Crystal Report(上)
- 在 Visual Studio .NET中使用Crystal Report(中)
- 在 Visual Studio .NET中使用Crystal Report(中)
- 在 Visual Studio .NET中使用Crystal Report(下)
- 在Visual Studio.NET中使用Crystal Report(中)
- 在 Visual Studio .NET中使用Crystal Report(下)
- 在Visual Studio.NET中使用Crystal Report (上)
- 在Visual Studio.NET中使用Crystal Report(下)
- 在Visual Studio.NET中使用Crystal Report(中)
- 在Visual Studio.NET中使用Crystal Report(下)
- 在 Visual Studio .NET中使用Crystal Report
- 在 Visual Studio .NET中使用Crystal Report(上)