I am trying to call a report based on a session variable that the user has chosen. The variable is a string and is passed to a Crystal 8 Report built using a stored procedure. Please look at my code and see whats wrong and why I would be getting an error of:Object reference not set to an instance of an object. THanks in Advanced.
Public Class WebForm1
Inherits System.Web.UI.Page
Dim oRpt As CrystalReportPluginLib.Report 'This is a strongly typed report being used
Dim crTables As Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
Dim crParameterFieldDefinition As ParameterFieldDefinition
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'' Set the Connection parameters
'' Using an OLEDB connection to a SQL Sever DB (Database: Pubs)
With crConnectionInfo
.DatabaseName = "Incident"
.ServerName = "AGFCDEV"
.UserID = "IncidentUser1"
.Password = "Scooby"
End With
'crTables = oRpt.Database.Tables
'Set the logon information for each table.
For Each crTable In crTables
'crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
' oRpt.Database.Tables.Item(1).SetDataSource("C:\Program Files\Common Files\ODBC\Data Sources\AGFCDEV.dsn"
'oRpt.Database.Tables.Item(1).LogOnInfo.ConnectionInfo.DatabaseName = "C:\Program Files\Common Files\ODBC\Data Sources\AGFCDEV.dsn"
'*****************************
' Pass the Stored Procedure parameter to the report
'*****************************
'Get the collection of parameters from the report
crParameterFieldDefinitions = oRpt.DataDefinition.ParameterFields
'Access the specified parameter from the collection
crParameterFieldDefinition = crParameterFieldDefinitions.Item("@ReportNumber"
'Get the current values from the parameter field. At this point
'there are zero values set.
crParameterValues = crParameterFieldDefinition.CurrentValues
'Set the current values for the numeric parameter field
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = ""
'Add the current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue)
'The current parameter values must be applied for the parameter field.
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
CrystalReportViewer1.ReportSource = oRpt
Public Class WebForm1
Inherits System.Web.UI.Page
Dim oRpt As CrystalReportPluginLib.Report 'This is a strongly typed report being used
Dim crTables As Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo
Dim crConnectionInfo As New ConnectionInfo
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
Dim crParameterFieldDefinition As ParameterFieldDefinition
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'' Set the Connection parameters
'' Using an OLEDB connection to a SQL Sever DB (Database: Pubs)
With crConnectionInfo
.DatabaseName = "Incident"
.ServerName = "AGFCDEV"
.UserID = "IncidentUser1"
.Password = "Scooby"
End With
'crTables = oRpt.Database.Tables
'Set the logon information for each table.
For Each crTable In crTables
'crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
' oRpt.Database.Tables.Item(1).SetDataSource("C:\Program Files\Common Files\ODBC\Data Sources\AGFCDEV.dsn"
'oRpt.Database.Tables.Item(1).LogOnInfo.ConnectionInfo.DatabaseName = "C:\Program Files\Common Files\ODBC\Data Sources\AGFCDEV.dsn"
'*****************************
' Pass the Stored Procedure parameter to the report
'*****************************
'Get the collection of parameters from the report
crParameterFieldDefinitions = oRpt.DataDefinition.ParameterFields
'Access the specified parameter from the collection
crParameterFieldDefinition = crParameterFieldDefinitions.Item("@ReportNumber"
'Get the current values from the parameter field. At this point
'there are zero values set.
crParameterValues = crParameterFieldDefinition.CurrentValues
'Set the current values for the numeric parameter field
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = ""
'Add the current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue)
'The current parameter values must be applied for the parameter field.
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
CrystalReportViewer1.ReportSource = oRpt