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

时间:2008-12-16 09:26:51

标签: asp.net crystal-reports

如何在ASP.Net 2.0中使用crystal Reports。 显示如何在生产服务器上部署Crystal Reports的任何示例/教程/示例。

3 个答案:

答案 0 :(得分:7)

刚刚经历过这种痛苦,这里有几个指针,希望能节省你的时间......

Crystal Reports on MSDN - 这里有很多好东西

Which Persistence Approach Should I Use with Crystal Reports - 提供有关如何最好地控制报表对象生命周期的详细信息和代码示例

This post也围绕报表对象生命周期提供了一些很好的建议

部署...最新的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中的标准参数屏幕只会带你到目前为止。如果您想要将参数呈现给用户变得复杂(例如,通过使参数取决于另一个参数的选择),您将需要滚动自己的参数屏幕。这非常简单,因为对象模型可让您访问有关参数的所有信息。我们沿着创建通用参数屏幕的路线走下去,该屏幕根据指向的报告中的参数进行构建。

答案 1 :(得分: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

答案 2 :(得分: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"
     />