繁体   English   中英

在Winform中打开Crystal报表

[英]Open Crystal Report in Winform

我创建了一个水晶报表,然后创建它,然后创建了一个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;处给出错误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

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

在您的窗体上放置一个CrystalReportViewer控件。 尽管在更高版本的Visual Studio中,您必须单独下载它 ,但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客户端配置文件更改为.NET Framework 4

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM