如何在 ASP.Net 2.0 中使用水晶报表。任何展示如何在生产服务器上部署 Crystal Reports 的示例/教程/示例。
3 回答
我自己刚刚经历过这种痛苦,这里有一些建议,希望能节省你的时间......
MSDN 上的 Crystal Reports - 这里有很多好东西
我应该对 Crystal Reports 使用哪种持久性方法- 提供有关如何最好地控制报表对象的生命周期的详细信息和代码示例
这篇文章还提供了一些关于报表对象生命周期的好建议
部署... 最新的 Crystal Reports 运行时不在 64 位环境中运行,因此如果部署到 64 位服务器,您要么必须将 IIS 配置为运行 32 位模式,要么使用以前版本的运行时。我最幸运的是与 VS2008 一起分发的运行时,这可以在
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5
我注意到您使用的是 ASP.NET 2.0 - 我确信有一个 VS2005 等效运行时。尝试让部署环境在项目的早期工作,因为它无疑会比你预期的更令人头疼。
最后,值得一提的是,Crystal Reports 中的标准参数屏幕仅能带您到此为止。如果您想对如何向用户呈现参数变得复杂(例如,通过使参数依赖于另一个参数的选择),您将需要滚动您自己的参数屏幕。这相当容易,因为对象模型使您可以访问您需要的有关参数的所有信息。我们已经创建了一个通用参数屏幕,该屏幕根据它所指向的报告中的参数构建自身。
这是我通常使用的代码:
'Generate the Report
Dim oRpt As New ReportDocument
Dim reportPath As String = Server.MapPath("crtTAL.rpt")
oRpt.Load(reportPath)
oRpt.SetDataSource(dsTAL)
If Not IO.Directory.Exists(tempLocation) Then
IO.Directory.CreateDirectory(tempLocation)
End If
If IO.File.Exists(tempLocation & filename) Then
IO.File.Delete(tempLocation & filename)
End If
' ********************************
' First we must create a new instance of the diskfiledestinationoptions class and
' set variable called crExportOptions to the exportoptions class of the reportdocument.
Dim crDiskFileDestinationOptions As New DiskFileDestinationOptions
Dim crExportOptions As ExportOptions = oRpt.ExportOptions
'Export to Word
'append a filename to the export path and set this file as the filename property for
'the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = tempLocation + filename
'set the required report ExportOptions properties
With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.WordForWindows
End With
'Once the export options have been set for the report, the report can be exported. The Export command
'does not take any arguments
Try
' Export the report
oRpt.Export()
oRpt.Close()
oRpt.Dispose()
projectCount = projectCount + 1
Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
errorList = errorList & dtrProjects.Item("Title") & "; "
End Try
这就是我通常使用的,Asp.net/C#
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
///create instance of class first
ReportDocument rpDoc = new ReportDocument();
///load the report
rpDoc.Load(@"TicketingBasic.rpt");
///pass the report to method for dataInfo
getDBInfo(rpDoc);
/// et the source for report to be displayed
CrystalReportViewer1.ReportSource = rpDoc;
}
protected static void getDBInfo(ReportDocument rpDoc)
{
///Connection Onject
ConnectionInfo cn = new ConnectionInfo();
///DataBase,Table, and Table Logon Info
Database db;
Tables tbl;
TableLogOnInfo tblLOI;
///Connection Declaration
cn.ServerName = "??????";
cn.DatabaseName = "???????";
cn.UserID = "???????";
cn.Password = "????????";
//table info getting from report
db = rpDoc.Database;
tbl = db.Tables;
///for each loop for all tables to be applied the connection info to
foreach (Table table in tbl)
{
tblLOI = table.LogOnInfo;
tblLOI.ConnectionInfo = cn;
table.ApplyLogOnInfo(tblLOI);
table.Location = "DBO." + table.Location.Substring(table.Location.LastIndexOf(".") + 1);
}
db.Dispose();
tbl.Dispose();
}
在 Aspx 方面:
<CR:CrystalReportViewer
ID="CrystalReportViewer1"
runat="server"
AutoDataBind="true"
EnableDatabaseLogonPrompt="false"
/>