Click here to Skip to main content
15,895,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a code for Crystal Reports and it is giving me an error.

C#
ReportDocument.Refresh();


An object reference is required for the non-static field, method, or property 'CrystalDecisions.CrystalReports.Engine.ReportDocument.Refresh()'

Why am I getting this error?

C#
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows;
using CrystalDecisions.ReportSource;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml.Linq;
using System.Web.SessionState;


namespace SACSCOCLogin1._1
{
    public partial class ReportA : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TextBoxINST_ID.Text = Session["inst_id"].ToString();
            CrystalReportViewer1.Visible = true;
            
            ReportDocument CrystalReport = new ReportDocument();
            CrystalReport.Load(Server.MapPath("~/Reports/ReportA.rpt"));
            CrystalReport.Refresh();
            CrystalReport.SetDatabaseLogon
            ("Admin", "master22", @"SQL", "Hot");
            CrystalReportViewer1.ReportSource = CrystalReport;
            CrystalReportViewer1.DataBind();
        }
    }
}
Posted
Updated 1-Dec-16 2:35am
v2

C#
ReportDocument CrystalReport = new ReportDocument();
ReportDocument.Refresh();
Second line is wrong, it should be like below
C#
CrystalReport.Refresh();
And call the Refresh() method after load() method
 
Share this answer
 
C#
Follow the below steps:
1. Open the crystal reports
2. got to File -> uncheck Save Data with Report
3. save the file

apply same with all subreports

now try to run the program.
 
Share this answer
 
C#
solution 1 is correct, some time Refresh() will also give error so you need to do below:

Follow the below steps:
1. Open the crystal reports
2. got to File -> uncheck Save Data with Report
3. save the file

apply same with all subreports

now try to run the program.
 
Share this answer
 
Comments
CHill60 2-Dec-16 11:50am    
If you need to amend a solution you can use the Improve solution link. Or, If you are going to post a second corrected solution then delete the original

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