Click here to Skip to main content
13,767,620 members
Rate this:
 
Please Sign up or sign in to vote.
I have a code for Crystal Reports and it is giving me an error.

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?

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 24-Feb-14 3:13am
Updated 1-Dec-16 3:35am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

ReportDocument CrystalReport = new ReportDocument();
ReportDocument.Refresh();
Second line is wrong, it should be like below
CrystalReport.Refresh();
And call the Refresh() method after load() method
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06-2016 | 2.8.181116.1 | Last Updated 1 Dec 2016
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100