Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal and Stored Procedures

Status
Not open for further replies.

scooby77

Programmer
Jun 9, 2003
9
0
0
US
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 = &quot;Incident&quot;
.ServerName = &quot;AGFCDEV&quot;
.UserID = &quot;IncidentUser1&quot;
.Password = &quot;Scooby&quot;
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(&quot;C:\Program Files\Common Files\ODBC\Data Sources\AGFCDEV.dsn&quot;)
'oRpt.Database.Tables.Item(1).LogOnInfo.ConnectionInfo.DatabaseName = &quot;C:\Program Files\Common Files\ODBC\Data Sources\AGFCDEV.dsn&quot;
'*****************************
' 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(&quot;@ReportNumber&quot;)

'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 = &quot;&quot;

'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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top