C
Chris
Hi,
I'm new to ASP.Net and Crystal but I've been playing with some samples
and have run into a problem.
If I put all my code into the Page_Init sub of a single form and run
that form, the Crystal report runs fine.
Now i am trying to create another web form where I can input
parameters, hit submit and have those parameters passed to the second
form to diplay the Report. Perhaps I don't understand how to pass them
from a web form. I created a sub routine in my 'Reports' form and
moved my code from the Page_Init sub to this sub. Then I try to call
the sub from my Submit action in my parameter entry form. The code
fails when the sub trys to execute the following:
CrystalReportViewer1.ReportSource = myReport
It fails with 'Object reference not set to an instance of an object'.
Here is the code that works if it is in the Page_Init sub:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents CrystalReportViewer1 As
CrystalDecisions.Web.CrystalReportViewer
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
Dim myReport As New ReportDocument()
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldValues As ParameterValues
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
myReport.Load("c:\inetpub\wwwroot\web_viewer_basic2\imp.rpt")
crParameterFieldDefinitions =
myReport.DataDefinition.ParameterFields
crParameterFieldDefinition =
crParameterFieldDefinitions.Item("Street Number")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterDiscreteValue = New ParameterDiscreteValue()
crParameterDiscreteValue.Value = "*400*" '1st current value
crParameterValues.Add(crParameterDiscreteValue)
**Snip, add more paramters. The values are hardcoded right
now.***
Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter
With crConnectionInfo
.ServerName = "DATABASE"
.DatabaseName = "dev"
.UserID = "userid"
.Password = password"
End With
**Snip, Loop through and login to all the tables**
CrystalReportViewer1.ReportSource = myReport
CrystalReportViewer1.DataBind()
End Sub
Can anyone give me some pointers on how to submit the parameters from
another form and pass them through to this form? I also suspect that
my declaration may be in the wrong place in the code.
Thanks,
Chris
I'm new to ASP.Net and Crystal but I've been playing with some samples
and have run into a problem.
If I put all my code into the Page_Init sub of a single form and run
that form, the Crystal report runs fine.
Now i am trying to create another web form where I can input
parameters, hit submit and have those parameters passed to the second
form to diplay the Report. Perhaps I don't understand how to pass them
from a web form. I created a sub routine in my 'Reports' form and
moved my code from the Page_Init sub to this sub. Then I try to call
the sub from my Submit action in my parameter entry form. The code
fails when the sub trys to execute the following:
CrystalReportViewer1.ReportSource = myReport
It fails with 'Object reference not set to an instance of an object'.
Here is the code that works if it is in the Page_Init sub:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents CrystalReportViewer1 As
CrystalDecisions.Web.CrystalReportViewer
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
Dim myReport As New ReportDocument()
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldValues As ParameterValues
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
myReport.Load("c:\inetpub\wwwroot\web_viewer_basic2\imp.rpt")
crParameterFieldDefinitions =
myReport.DataDefinition.ParameterFields
crParameterFieldDefinition =
crParameterFieldDefinitions.Item("Street Number")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterDiscreteValue = New ParameterDiscreteValue()
crParameterDiscreteValue.Value = "*400*" '1st current value
crParameterValues.Add(crParameterDiscreteValue)
**Snip, add more paramters. The values are hardcoded right
now.***
Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter
With crConnectionInfo
.ServerName = "DATABASE"
.DatabaseName = "dev"
.UserID = "userid"
.Password = password"
End With
**Snip, Loop through and login to all the tables**
CrystalReportViewer1.ReportSource = myReport
CrystalReportViewer1.DataBind()
End Sub
Can anyone give me some pointers on how to submit the parameters from
another form and pass them through to this form? I also suspect that
my declaration may be in the wrong place in the code.
Thanks,
Chris