Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: report load error Post Reply Post New Topic
Author Message
djung527
Newbie
Newbie


Joined: 08 Jun 2009
Online Status: Offline
Posts: 4
Quote djung527 Replybullet Topic: report load error
    Posted: 08 Jun 2009 at 8:29am
Hello, first off, bought this book from amazon.com and it has done wonders for me. Thank you so much.

While trying out some of the code in this book, I get the following message.

Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:

Line 16:     Private Sub ConfigureReport()
Line 17:        myReport.Load(Server.MapPath("CrystalReport1.rpt"))

This is the code from p277.

I thought I follow the book's example since the page load even indeed does time off too fast and must reload the page when mouse clicking.


My Project is a simple ASP.net Crystal Reports Website. Nothing special, just trying to load a crystal report I have made using the stand alone crystal report designer. This report is located in the project directory. Using page load event works fine, but seems to hit a wall when using page init which then runs the configureReport() sub.

Can someone help me? what am i missing? FYI, I dropped in the CrystalReportView control on to the forms page.

Below is my entire code if you wish to see it.

Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Web
Partial Class QR
    Inherits System.Web.UI.Page
    Dim myReport As ReportDocument
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        If Session("myReport") Is Nothing Then
            ConfigureReport()
        Else
            myReport = CType(Session("myReport"), ReportDocument)
        End If
        CrystalReportViewer1.ReportSource = myReport
    End Sub

    Private Sub ConfigureReport()
        myReport.Load(Server.MapPath("CrystalReport1.rpt"))
        'Custom Report Modification
        'Load user login credentials
        'code for login credentials will be added later..
        Session("myReport") = myReport
    End Sub
End Class



Thank you again!

IP IP Logged
djung527
Newbie
Newbie


Joined: 08 Jun 2009
Online Status: Offline
Posts: 4
Quote djung527 Replybullet Posted: 08 Jun 2009 at 11:58am
Ok, after downloading the code sample from this website I noticed there is a subtle difference in the code between the download and the one on page 277.

Where myReport is being declared, there is a missing keyword, "NEW" in the book. Adding this keyword works.

ie; Dim myReport As New ReportDocument

I am a newbie in .net programming and programming in general so please forgive me if this was an obvious mistake.

Thanks
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.