问题描述
我创建了一个水晶报表,然后在创建它之后,我创建了一个 winform,我在其中导入了水晶报表库(以代码显示)并使用报表查看器查看报表,但我无法查看报告,代码,我是 Crytal Reports 的新手,我所做的代码是:
I've created a crystal report then after creating it, I've created a winform where I've import crystal report library (shown in code) and used a report viewer to view the report but i not able to view the report, the code, i am new with Crytal Reports, the code I've done is :
代码:
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; 给出错误,错误是
it's giving error at reportViewer1.ReportSource = cryRpt; and the error is
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:UsersAhsanDesktopPROJECT INVENTORY SOFTWAREInventorySoftwareInventorySoftwareForm1.cs 34 27 InventorySoftware
推荐答案
您为 Crystal Reports 使用了错误的类/控件.
You're using the wrong classes/controls for Crystal Reports.
在表单上放置一个 CrystalReportViewer 控件.尽管使用更高版本的 Visual Studio,您必须 下载单独,它仍然是随 VS2008 提供的.
Place a CrystalReportViewer control on your form. Although with later versions of Visual Studio you have to download it separately, it was still shipped with VS2008.
如果您在工具箱中没有看到它,请右键单击工具箱中的任意位置,然后单击选择项目...".
If you don't see it in your toolbox, right-click anywhere in your toolbox and click "Choose Items...".
检查并按 OK 后,它应该被添加到您的工具箱中.删除您现有的报表控件并将水晶报表查看器放在表单上:
After checking it and pressing OK, it should be added to your toolbox. Remove your existing report control and drop a crystal report viewer on the form:
当您将查看器放在项目上时,必要的水晶参考将被添加到您的项目中.
The necessary crystal references will be added to your project when you drop the viewer on it.
将此 using 指令添加到代码隐藏的顶部:
Add this using directive to the top of your code-behind:
using CrystalDecisions.CrystalReports.Engine;
然后将您的报告加载到查看器中:
Then load your report into the viewer:
var cryRpt = new ReportDocument();
cryRpt.Load(@"C:UsersAhsanDesktopPROJECT INVENTORY SOFTWAREInventorySoftwareInventorySoftwareCrystalReport1.rpt");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
将目标框架从 .NET Framework 4 Client Profile 更改为 .NET Framework 4:
Change the targeted framework from .NET Framework 4 Client Profile to .NET Framework 4:
这篇关于在 Winform 中打开水晶报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)