如何在ASP.NET中使用Crystal Reports?

6
如何在ASP.Net 2.0中使用Crystal Reports。有没有样例/教程/示例可以展示如何在生产服务器上部署Crystal Reports。
3个回答

7

我自己刚经历了这样的痛苦,以下是一些指针,希望能为您节省时间...

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中的标准参数屏幕只能带您走那么远。如果您想以复杂的方式向用户呈现参数(例如,通过选择另一个参数而依赖于参数),则需要编写自己的参数屏幕。这很容易,因为对象模型为您提供了有关参数的所有信息。我们采用了创建通用参数屏幕的方法,该屏幕根据指向的报表中找到的参数来构建自己。


0

这是我通常使用的代码:

'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

0

这通常是我使用的,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"
     />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接