Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am trying to create a crystal report usinsg data set but getting the errors

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


coding i have done is..

C#
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;
        

    }
Posted
Updated 1-Oct-11 12:51pm
v2

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.
 
Share this answer
 
CrystalReportViewer report = new CrystalReportViewer();
 
Share this answer
 
you need to create the .rpt first and then load it to ReportDocument

Try this :

C#
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 :)
 
Share this answer
 
protected void Page_Load(object sender, EventArgs e)
{

Reportdocument report = new Reportdocument();//here i am getting error
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;


}


replace....your code with the above.........i hope it will help you
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900