Crystal Report not loading with SQL Server logon info

Hi,

I get the following error when I try to connect to my server to run a crystal report and it highlights the code in purple:

Object reference not set to an instance of an object

First I ren the code without the parameter and it worked fine, but I don't know why it is not working with the parameter added.

rpt =New CrystalReport1()

Dim reportPathAsString ="C:\Crystal Report\Crystalreport1.rpt"

Dim myConnectionInfoAs CrystalDecisions.Shared.ConnectionInfo =New CrystalDecisions.Shared.ConnectionInfo()

myConnectionInfo.ServerName =[servername here]

myConnectionInfo.DatabaseName ="[database name here]"

myConnectionInfo.UserID ="[user name here]"

myConnectionInfo.Password ="[password here]"

Dim myTableLogOnInfosAs CrystalDecisions.Shared.TableLogOnInfos = CView.LogOnInfo

ForEach myTableLogOnInfoAs CrystalDecisions.Shared.TableLogOnInfoIn myTableLogOnInfos

myTableLogOnInfo.ConnectionInfo = myConnectionInfo

Next

CView.ReportSource = rpt

Dim field1As ParameterField =Me.CView.ParameterFieldInfo(0)

Dim val1As ParameterDiscreteValue =New ParameterDiscreteValue

val1.Value ="2/20/2007"

field1.CurrentValues.Add(val1)

rpt.Load(reportPath)

I would really appretiate the help.

Lawrence

[3034 byte] By [Lawrence007] at [2008-1-1]
# 1

I got the solution to those who want it:

Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo)

Dim myTableLogOnInfos As CrystalDecisions.Shared.TableLogOnInfos = CView.LogOnInfo

For Each myTableLogOnInfo As CrystalDecisions.Shared.TableLogOnInfo In myTableLogOnInfos

myTableLogOnInfo.ConnectionInfo = myConnectionInfo

Next

End Sub

And then:

Dim myConnectionInfo As CrystalDecisions.Shared.ConnectionInfo = New CrystalDecisions.Shared.ConnectionInfo()
myConnectionInfo.ServerName = [server]
myConnectionInfo.DatabaseName = [database]
myConnectionInfo.UserID = [user Name]
myConnectionInfo.Password = [password]
CView.ReportSource = rpt
Dim field1 As ParameterField = Me.CView.ParameterFieldInfo(0)
Dim val1 As ParameterDiscreteValue = New ParameterDiscreteValue
val1.Value = TRDate.Text
field1.CurrentValues.Add(val1)
rpt.Load(reportPath)


SetDBLogonForReport(myConnectionInfo)

the important step in blue

Lawrence007 at 2007-9-12 > top of Msdn Tech,Visual Basic,Visual Basic General...