Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Object reference not set to an instance of an object.

Object reference not set to an instance of an object.

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netvisual-studiosysadmindebugging
13 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BalasubramanianK
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • B BalasubramanianK

      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.

      D Offline
      D Offline
      Dinesh Mani
      wrote on last edited by
      #2

      What is the error that you get at the end when you step through the code?

      B 1 Reply Last reply
      0
      • D Dinesh Mani

        What is the error that you get at the end when you step through the code?

        B Offline
        B Offline
        BalasubramanianK
        wrote on last edited by
        #3

        "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.

        D 1 Reply Last reply
        0
        • B BalasubramanianK

          "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.

          D Offline
          D Offline
          Dinesh Mani
          wrote on last edited by
          #4

          During runtime check if rptDoc holds a value. May be rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt")); returns null.

          B 1 Reply Last reply
          0
          • D Dinesh Mani

            During runtime check if rptDoc holds a value. May be rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt")); returns null.

            B Offline
            B Offline
            BalasubramanianK
            wrote on last edited by
            #5

            "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.

            D 1 Reply Last reply
            0
            • B BalasubramanianK

              "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.

              D Offline
              D Offline
              Dinesh Mani
              wrote on last edited by
              #6

              If the Reports folder is available in the application root then try rptDoc.Load("~/Reports/STTCertificateAnnual1.rpt"); HTH!

              B 1 Reply Last reply
              0
              • D Dinesh Mani

                If the Reports folder is available in the application root then try rptDoc.Load("~/Reports/STTCertificateAnnual1.rpt"); HTH!

                B Offline
                B Offline
                BalasubramanianK
                wrote on last edited by
                #7

                This line throws error as "Load Report Failed"

                Balasubramanian K.

                D 1 Reply Last reply
                0
                • B BalasubramanianK

                  This line throws error as "Load Report Failed"

                  Balasubramanian K.

                  D Offline
                  D Offline
                  Dinesh Mani
                  wrote on last edited by
                  #8

                  What is the value you get when you try Server.MapPath("Reports/STTCertificateAnnual1.rpt") in the immediate window?

                  B 1 Reply Last reply
                  0
                  • D Dinesh Mani

                    What is the value you get when you try Server.MapPath("Reports/STTCertificateAnnual1.rpt") in the immediate window?

                    B Offline
                    B Offline
                    BalasubramanianK
                    wrote on last edited by
                    #9

                    "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.

                    D 1 Reply Last reply
                    0
                    • B BalasubramanianK

                      "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.

                      D Offline
                      D Offline
                      Dinesh Mani
                      wrote on last edited by
                      #10

                      Check the value of "rptDoc.IsLoaded" when using the original code rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt"));

                      B 1 Reply Last reply
                      0
                      • D Dinesh Mani

                        Check the value of "rptDoc.IsLoaded" when using the original code rptDoc.Load(Server.MapPath("Reports/STTCertificateAnnual1.rpt"));

                        B Offline
                        B Offline
                        BalasubramanianK
                        wrote on last edited by
                        #11

                        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.

                        D 1 Reply Last reply
                        0
                        • B BalasubramanianK

                          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.

                          D Offline
                          D Offline
                          Dinesh Mani
                          wrote on last edited by
                          #12

                          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.

                          B 1 Reply Last reply
                          0
                          • D Dinesh Mani

                            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.

                            B Offline
                            B Offline
                            BalasubramanianK
                            wrote on last edited by
                            #13

                            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.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups