创建Crystal报表时出现问题 [英] Problem in Creating Crystal Report

查看:92
本文介绍了创建Crystal报表时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建水晶报告usinsg数据集,但出现错误

i am trying to create a crystal report usinsg data set but getting the errors

Error	1	'_Default.CrystalReportViewer1' is a 'field' but is used like a 'type



我做的编码是..



coding i have done is..

protected void Page_Load(object sender, EventArgs e)
    {

        CrystalReportViewer1 report = new CrystalReportViewer1();//here i am getting error
        CrystalReportViewer1.Visible = true;
        DataSet ds = new DataSet("DataSet1");
        DataTable table = new DataTable("DataSet1");

        table.Columns.Add("username", typeof(System.String));
        table.Columns.Add("bookno", typeof(System.String));

        DataRow row = table.NewRow();
        row["username"] = "Farooq";
        row["bookno"] = "hyden";
        report.SetDataSource(ds);
        CrystalReportViewer1.ReportSource = report;
        

    }

推荐答案

您正在使用变量CrystalReportViewer1(类型为 ReportDocument [ 如何在项目中使用Crystal Report? [使用带有数据集的C#创建Crystal报表 [
You are using the variable CrystalReportViewer1 (of type CrystalReportViewer[^]) as a type. So your code really makes no sense.
I suspect you wanted to create a new ReportDocument[^] to attach to the CrystalReportViewer1.

Have a look at the below CP articles on how to use CrystalReportViewer. They are ''old'' but should still be useful.
How to use Crystal Report in your project?[^]
Creating Crystal Reports using C# with Datasets[^]

I hope this helps.


CrystalReportViewer report = new CrystalReportViewer();
CrystalReportViewer report = new CrystalReportViewer();


您需要先创建 .rpt 然后将其加载到 ReportDocument

试试这个:

you need to create the .rpt first and then load it to ReportDocument

Try this :

protected void Page_Load(object sender, EventArgs e)
    {
 
        ReportDocument crypt = new ReportDocument();
        CrystalReportViewer1.Visible = true;
        DataSet ds = new DataSet("DataSet1");
        DataTable table = new DataTable("DataSet1");
 
        table.Columns.Add("username", typeof(System.String));
        table.Columns.Add("bookno", typeof(System.String));
 
        DataRow row = table.NewRow();
        row["username"] = "Farooq";
        row["bookno"] = "hyden";
        ReportDocument crypt = new ReportDocument();
            string path="D:\\Projects\\CrystalDemo\\CrystalDemo\\CrystalReport1.rpt";
            crypt.Load(path);
            crypt.SetDataSource(ds);
            crystalReportViewer1.ReportSource = crypt;
            crystalReportViewer1.Refresh();
        
 
    }



有关更多详细信息,请检查
[



for more details check THIS[^]

hope it helps :)


这篇关于创建Crystal报表时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆