【问题标题】:Open Crystal Report in Winform在 Winform 中打开水晶报表
【发布时间】:2014-05-09 04:31:57
【问题描述】:

我创建了一个水晶报表,然后在创建它之后,我创建了一个 winform,我在其中导入了水晶报表库(以代码显示)并使用报表查看器查看报表,但我无法查看报告,代码,我是 Crytal Reports 的新手,我所做的代码是:

代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace InventorySoftware
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            this.reportViewer1.RefreshReport();



        }

        private void button1_Click(object sender, EventArgs e)
        {
            //string ReportSources = "";
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load("C:\\Users\\Ahsan\\Desktop\\PROJECT INVENTORY SOFTWARE\\InventorySoftware\\InventorySoftware\\CrystalReport1.rpt");
            reportViewer1.ReportSource = cryRpt;
            reportViewer1.Refresh();

        }
    }
}

reportViewer1.ReportSource = cryRpt; 出现错误,错误是

Error   1   'Microsoft.Reporting.WinForms.ReportViewer' does not contain a definition for 'ReportSource' and no extension method 'ReportSource' accepting a first argument of type 'Microsoft.Reporting.WinForms.ReportViewer' could be found (are you missing a using directive or an assembly reference?) C:\Users\Ahsan\Desktop\PROJECT INVENTORY SOFTWARE\InventorySoftware\InventorySoftware\Form1.cs  34  27  InventorySoftware

【问题讨论】:

    标签: c# winforms visual-studio-2008 crystal-reports


    【解决方案1】:

    您为 Crystal Reports 使用了错误的类/控件。

    在您的表单上放置一个CrystalReportViewer 控件。虽然使用更高版本的 Visual Studio 你必须download it separately,但它仍然是shipped with VS2008

    如果您在工具箱中没有看到它,请右键单击工具箱中的任意位置,然后单击“选择项目...”。

    检查并按 OK 后,它应该被添加到您的工具箱中。删除您现有的报表控件并将水晶报表查看器放在表单上:

    当您将查看器放在项目上时,必要的水晶参考将被添加到您的项目中。

    将此using 指令添加到代码隐藏的顶部:

    using CrystalDecisions.CrystalReports.Engine;
    

    然后将您的报告加载到查看器中:

    var cryRpt = new ReportDocument();
    cryRpt.Load(@"C:\Users\Ahsan\Desktop\PROJECT INVENTORY SOFTWARE\InventorySoftware\InventorySoftware\CrystalReport1.rpt");
    crystalReportViewer1.ReportSource = cryRpt;
    crystalReportViewer1.Refresh();
    

    编辑:

    将目标框架从 .NET Framework 4 Client Profile 更改为 .NET Framework 4

    【讨论】:

    • 感谢您的回复,但我的VS2008中没有名为CrystalReportViewer的工具,但只有ReportViewer是
    • 水晶报表参考很多,应该加哪一个?
    • 我已经用水晶报告添加了所有参考,但仍然是同样的错误:(
    • 是的,兄弟,它在客户资料上,最后我弄明白了 :) 我很高兴 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多