Object reference not set to an instance of an object.
-
Hi All, I am using Asp.Net 2.0 with C#, Crystal Reports (VS 2005). I am trying to open a report by passing 4 parameters but it gives an error called "Object reference not set to an instance of an object.". While I debug, I did not get err at any line. It goes smooth but finally it gives an error. Can you guide me?. Here is my code.
crvSTT.RefreshReport();
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt"));
ParameterFields paramFields = new ParameterFields();ParameterField pfYear = new ParameterField();
ParameterField pfBACode = new ParameterField();
ParameterField pfFromClientCode = new ParameterField();
ParameterField pfToClientCode = new ParameterField();pfBACode.ParameterFieldName = "pBACode";
ParameterDiscreteValue pdvBACode;
pdvBACode = new ParameterDiscreteValue();
pdvBACode.Value = strUserId;
pfBACode.CurrentValues.Add(pdvBACode);
paramFields.Add(pfBACode);pfFromClientCode.ParameterFieldName = "pFromClientCode";
ParameterDiscreteValue pdvFromClientCode;
pdvFromClientCode = new ParameterDiscreteValue();
pdvFromClientCode.Value = txtFromCC.Text;
pfFromClientCode.CurrentValues.Add(pdvFromClientCode);
paramFields.Add(pfFromClientCode);pfToClientCode.ParameterFieldName = "pToClientCode";
ParameterDiscreteValue pdvToClientCode;
pdvToClientCode = new ParameterDiscreteValue();
pdvToClientCode.Value = txtToCC.Text;
pfToClientCode.CurrentValues.Add(pdvToClientCode);
paramFields.Add(pfToClientCode);pfYear.ParameterFieldName = "pYear";
ParameterDiscreteValue pdvYear;
pdvYear = new ParameterDiscreteValue();
pdvYear.Value = "Current";
pfYear.CurrentValues.Add(pdvYear);
paramFields.Add(pfYear);crvSTT.ParameterFieldInfo = paramFields;
crvSTT.ReportSource = rptDoc;
crvSTT.DataBind();Thanks in Adv :omg:
Balasubramanian K.
-
Hi All, I am using Asp.Net 2.0 with C#, Crystal Reports (VS 2005). I am trying to open a report by passing 4 parameters but it gives an error called "Object reference not set to an instance of an object.". While I debug, I did not get err at any line. It goes smooth but finally it gives an error. Can you guide me?. Here is my code.
crvSTT.RefreshReport();
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt"));
ParameterFields paramFields = new ParameterFields();ParameterField pfYear = new ParameterField();
ParameterField pfBACode = new ParameterField();
ParameterField pfFromClientCode = new ParameterField();
ParameterField pfToClientCode = new ParameterField();pfBACode.ParameterFieldName = "pBACode";
ParameterDiscreteValue pdvBACode;
pdvBACode = new ParameterDiscreteValue();
pdvBACode.Value = strUserId;
pfBACode.CurrentValues.Add(pdvBACode);
paramFields.Add(pfBACode);pfFromClientCode.ParameterFieldName = "pFromClientCode";
ParameterDiscreteValue pdvFromClientCode;
pdvFromClientCode = new ParameterDiscreteValue();
pdvFromClientCode.Value = txtFromCC.Text;
pfFromClientCode.CurrentValues.Add(pdvFromClientCode);
paramFields.Add(pfFromClientCode);pfToClientCode.ParameterFieldName = "pToClientCode";
ParameterDiscreteValue pdvToClientCode;
pdvToClientCode = new ParameterDiscreteValue();
pdvToClientCode.Value = txtToCC.Text;
pfToClientCode.CurrentValues.Add(pdvToClientCode);
paramFields.Add(pfToClientCode);pfYear.ParameterFieldName = "pYear";
ParameterDiscreteValue pdvYear;
pdvYear = new ParameterDiscreteValue();
pdvYear.Value = "Current";
pfYear.CurrentValues.Add(pdvYear);
paramFields.Add(pfYear);crvSTT.ParameterFieldInfo = paramFields;
crvSTT.ReportSource = rptDoc;
crvSTT.DataBind();Thanks in Adv :omg:
Balasubramanian K.
What is the error that you get at the end when you step through the code?
-
What is the error that you get at the end when you step through the code?
"Object reference not set to an instance of an object." is the error I got at my page by came through all the steps of my codes.
Balasubramanian K.
-
"Object reference not set to an instance of an object." is the error I got at my page by came through all the steps of my codes.
Balasubramanian K.
During runtime check if rptDoc holds a value. May be
rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt"));
returns null. -
During runtime check if rptDoc holds a value. May be
rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt"));
returns null."Expression has been evaluated and has no value" is the value I am getting at rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt")); But the report is available in proper place. What I have to do to solve this?
Balasubramanian K.
-
"Expression has been evaluated and has no value" is the value I am getting at rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt")); But the report is available in proper place. What I have to do to solve this?
Balasubramanian K.
If the Reports folder is available in the application root then try
rptDoc.Load("~/Reports/STTCertificateAnnual1.rpt");
HTH! -
If the Reports folder is available in the application root then try
rptDoc.Load("~/Reports/STTCertificateAnnual1.rpt");
HTH!This line throws error as "Load Report Failed"
Balasubramanian K.
-
This line throws error as "Load Report Failed"
Balasubramanian K.
What is the value you get when you try
Server.MapPath("Reports/STTCertificateAnnual1.rpt")
in the immediate window? -
What is the value you get when you try
Server.MapPath("Reports/STTCertificateAnnual1.rpt")
in the immediate window?"Expression has been evaluated and has no value" is the value I am getting at immediate window of rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt"));
Balasubramanian K.
-
"Expression has been evaluated and has no value" is the value I am getting at immediate window of rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt"));
Balasubramanian K.
Check the value of "
rptDoc.IsLoaded
" when using the original coderptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt"));
-
Check the value of "
rptDoc.IsLoaded
" when using the original coderptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt"));
It returns true. I am getting the business objects' symbols(Export, print, Page nagivator, etc.) also at my page followed by my error.
Balasubramanian K.
-
It returns true. I am getting the business objects' symbols(Export, print, Page nagivator, etc.) also at my page followed by my error.
Balasubramanian K.
In that case, I've lead you in the wrong direction. The report document is not the cause of the error. Sorry. Check the parms collection for values. Also check if the no of params you are passing matches what the report is expecting. Other than that, I've no clues to what is going wrong.
-
In that case, I've lead you in the wrong direction. The report document is not the cause of the error. Sorry. Check the parms collection for values. Also check if the no of params you are passing matches what the report is expecting. Other than that, I've no clues to what is going wrong.
Actually, I pass 4 parameters only. If I pass the same into report directly, I can able to view the report. Through coding, I am trapped. However, you have spent your time for me. Thanks a lot.
Balasubramanian K.