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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why are stored proc params being passed NULL?

Status
Not open for further replies.

brailian

Programmer
Oct 11, 2001
11
US
VB6, RDC, ODBC, SQL Server

This is probably very easy, I'm just new to RDC (been using OCX for years)

I have a VERY simple report using ODBC, based on a stored proc with 1 char param. It works fine in the Crystal Designer.

In VB6, I add the viewer to a form and add this code:

Private Sub Form_Load()
Dim app As CRAXDRT.Application
Dim myReport As CRAXDRT.Report

Set app = New CRAXDRT.Application
Set myReport = app.OpenReport("c:\work\xtest.rpt")
myReport.Database.Tables(1).SetLogOnInfo "MyDSN", "MyTable", "sa", "MyPwd"
myReport.ParameterFields(1).AddCurrentValue "TheValue"
myReport.EnableParameterPrompting = False

CRViewer1.ReportSource = myReport
Form2.WindowState = vbMaximized
Form2.Show
myReport.DiscardSavedData
CRViewer1.ViewReport
End Sub

No error occurs, but the report shows no data. The stored procedure is being passed NULL instead of "TheValue" (I did a trace to confirm).

What am I doing wrong?

Note: If I don't set EnableParameterPrompting = False, then crystal prompts for the value and if I type it in, it gets passed properly. (again, confirmed with trace)
 
I set the values of parameters as required through Delphi code using the syntax :
CRReport.ParameterFields[1].SetCurrentValue('The Value', crStringField);
... that's assuming that it is a String Field you're dealing with.
Hope that this helps.
Steve
 
if there is only one parameter then the parameter field is
ParameterFields(0) not ParameterFields(1)
 
Actually, it is 1 not 0. You are probably thinking of the API. The RDC appears to be 1-based. And like I said, it doesn't give an error, it just passes NULL to my stored procedure.
 
I make use of the 'SetCurrentValue' rather than 'AddCurrentValue' or is this the equivalent in VB as compared with Delphi ?
Are you able to use 'SetCurrentValue' ?
Steve
 
Actually, VB Intellisense did not reveal that there was a SetCurrentValue method, so I was using the AddCurrentValue method instead which appears to do the same thing. However, when I typed out SetCurrentValue, it accepted it. Same problem, though.

However, I just solved it. On a hunch I moved the DiscardSavedData method call above the code to set the parameter value and that fixed it! Why??? I have no idea. Weird, I wouldn't have thought SavedData had anything to do with the new data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top