2 Replies - 2317 Views - Last Post: 09 April 2009 - 03:49 AM Rate Topic: -----

#1 newProgram  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 160
  • Joined: 28-October 08

Object Reference not set to an intance of an Object

Post icon  Posted 07 April 2009 - 07:37 PM

Hi to All,

I have a codes and it is working properly. The only problem is at the top of my page I always having this error message, "Object Reference not set to an instance of an object". I can't find where is the cause of the error message. Any help? Thanks in advance.

Here's my codes:

		connect.Open();

		ReportDocument report;

		ParameterFields pFields = null;
		ParameterField pfMonth = null;
		ParameterField pfYear = null;
		ParameterDiscreteValue valueMonth = null;
		ParameterDiscreteValue valueYear = null;

		DataSet ds = (DataSet)Session["dataset"];

		try
		{
			pFields = new ParameterFields();
			pfMonth = new ParameterField();
			pfYear = new ParameterField();
			valueMonth = new ParameterDiscreteValue();
			valueYear = new ParameterDiscreteValue();

			valueMonth.Value = Session["month"].ToString();
			valueYear.Value = Session["year"].ToString();
			pfMonth.Name = "month";
			pfYear.Name = "year";
			pfMonth.CurrentValues.Add(valueMonth);
			pfYear.CurrentValues.Add(valueYear);
			pFields.Add(pfMonth);
			pFields.Add(pfYear);

			crview.ParameterFieldInfo = pFields;
			crview.RefreshReport();

			report = new ReportDocument();
			report.Load(Server.MapPath("cdrMonth.rpt"));
			report.SetDataSource(ds.Tables[0]);
			report.Refresh();

			crview.ReportSource = report;
			crview.DataBind();

			lblError.Visible = false;
		}
		catch (Exception ex)
		{
			lblError.Text = ex.Message;
			lblError.Visible = true;
		}
		finally
		{
			if (ds != null)
			{
				ds.Dispose();
				ds = null;
			}

			pFields = null;
			pfMonth = null;
			pfYear = null;
			valueMonth = null;
			valueYear = null;

			connect.Close();
		}



Is This A Good Question/Topic? 0
  • +

Replies To: Object Reference not set to an intance of an Object

#2 doWhileSomething  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 96
  • Joined: 08-January 09

Re: Object Reference not set to an intance of an Object

Posted 08 April 2009 - 05:50 PM

It's hard to tell for us as well :)

If your seeing the error along with the generated page, chances are your writing the error to the page some place.

The error states that some object needs to be instantiated (a new instance of the object) before it can be used/referenced. Put a break point on the first piece of code that gets exectued by the page, follow it through the entire cycle until the error happens. If the page itself is not blowing up, chance are it's trapped inside a try..catch block.
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Object Reference not set to an intance of an Object

Posted 09 April 2009 - 03:49 AM

have you tried breakpointing and walking through the code to see where the error is? That is the purpose of the debugger.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1