views:

464

answers:

1

I have made a new report using Crystal Reports 8.5 (report1) which uses a stored procedure as its data source. The stored procedure has 2 input parameters (@p1 and @p2) and when I enter some test data for @p1 and @p2 within crystal report IDE , every thing is all right. Then, I added the report1 in visual basic 6.0 IDE and added a new form (form1) and a crystal report viewer control on form1. Now please help me: I wanna to show the report1. What codes exactly should I write to show it?How send data user has entered to the stored procedure parameters via application? I also get this error messsage: the server has not been opened yet"

What's wrong?

A: 

Specifying a report

Assumes that SampleReport has been added to your .Net project:

Dim parameter1 As CrystalDecisions.Shared.ParameterField
Dim parameter2 As CrystalDecisions.Shared.ParameterField

With SampleReport
    .SetDatabaseLogon("user", "password", "server", "database")
    'locate first parameter in report
    parameter1 = .ParameterFields.Find("@p1", "")
    'locate second parameter in report
    parameter2 = .ParameterFields.Find("@p2", "")
End With

'create a new discrete-parameter value
Dim stringValue As New CrystalDecisions.Shared.ParameterDiscreteValue()
stringValue.Value = "USA"

'assign it to the parameter's current values collection
parameter1.CurrentValues.Add(stringValue)

'create a new discrete-parameter value
Dim numberValue As New CrystalDecisions.Shared.ParameterDiscreteValue()
numberValue.Value = 100

'assign it to the parameter's current values collection
parameter2.CurrentValues.Add(numberValue)

With Me.CrystalReportViewer1
    .ReportSource = SampleReport
End With
Craig
Craig,As I said I have added the report to VB6 project and did what you had said (3 lines above) but still I can not show it. Now I have 3 questions:1 - Do I need to fill a recordset as the data source of the report at runtime? 2 - How I can send parameters to the stored procedure in order to show the report?3- What about the message: "The server has not yet been opened" ?
odiseh
1. If you add the stored procedure to the report as a 'table', then CR will do all of the work. You could dynamically assign the recordset in code, but this is more complicated than just adding it to the report in the designer.2. I would add the stored procedure to the report as its sole 'table'. You can do this in Crystal Reports | Database | Database Expert.. The report will recognize the SP's parameters. When you run the report, you can set the parameters' values in code or simply allow the report to prompt the user.
Craig
Oh, finally found it....:)1- as you kindly said, there is not need to fill a recordset after adding a SP to the report at design time.2 - if a for each loop, using a select statement we choose every parameter and assign its value.3 - we need to use SetLogOnInfo method Craig, Thank you very much3 -
odiseh