?
Solved

Can ASP.NET webform knows the parameter fields for Crystal Report?

Posted on 2004-11-09
16
Medium Priority
?
1,076 Views
Last Modified: 2012-06-27
Hi..

I am using asp.net with crystal report 10 and storing in Crystal Enterprise 10. Wondering is there a way to know the parameter input fields from the crystal report(.rpt) itself??

Otherwise is there any good suggestions for many crystal reports with different parameter values?
Am trying to think of a flexible/good ways for storing the paramters field and maybe default values..
so as to display correctly for users to input on the web form.

Any advices/suggestions.
Thanks !
0
Comment
Question by:neele
  • 8
  • 5
  • 2
15 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 12544522
Not sure about through CE but in VB with the RDC they are available.

crRptObject.ParameterFields(i).Name

If you wish to see the code I use to pass not only parameters but all information I'll post it.

mlmcc
0
 
LVL 2

Author Comment

by:neele
ID: 12555574
So usually how you all manage for web based application? as in many crystal reports and different parameters (some parameter might be same type e.g. DATE)

Am new to CR/CE etc haha usually is using RDC right? ........

Do u mean email me?? Would like to learn more..on managing CR through the Vb.net/ASp.net layer
VB is fine.

Thanks !
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 12557117
>> email.  No I will post either here or in a downloadable site.

mlmcc
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 10

Expert Comment

by:ebolek
ID: 12557528
Yes there is. In .net It is like this.Yous et parameetrs at runtime like this. Youc an look at the code and see how I get reference to the parameter desired as well

internal static void CreateParameter(ref ReportDocument report, string ParameterName, object value)
            {
                  ParameterDiscreteValue  ParameterDiscreteValue;
                  ParameterValues  ParameterValues;
                  ParameterFieldDefinition param = report.DataDefinition.ParameterFields[ParameterName];
                  ParameterValues = new CrystalDecisions.Shared.ParameterValues();
                  ParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();      
                  ParameterDiscreteValue.Value = value;      
                  ParameterValues.Add(ParameterDiscreteValue);
                  param.CurrentValues.Clear();
                  param.DefaultValues.Clear();  
                  param.ApplyCurrentValues(ParameterValues);
            }
0
 
LVL 2

Author Comment

by:neele
ID: 12566287
Hi mlmcc : is the code LONG/LENGTHY otherwise you can post it here.

Hi ebolek can you explani your code? It seem only..a function to take in the report and setting the parameters to the report?

But I wish to find out ways of "detecting" the parameter fields in that Selected Report. As I will be having more than 1 reports...
I am trying to find ways to make my web form flexible : Using 1 web form for loading the Crystal Report parameters based on user selection. If i can know the parameters I am thinking that I can e.g. if is a DATE field then I load my dropdown list with year/month and set it visible. ...bla bla..

Guess you all should have done something similar right?

Thanks !!
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 12576962
It is lengthy.  I'll see if I can post it.  Might take 2 comments.

mlmcc
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 500 total points
ID: 12576967
Here goes.  The comments at the top should explain it.  I have a newer version(not here though) that breaks this into several separate procedures.

Option Explicit
    Private crApp As CRAXDRT.Application
    Private crRpt As CRAXDRT.Report
'
'   Use of crPreviewReport
'
'       txtReportName - Full path and filename for the report to be displayed
'           eg  \\cts\ctssql\reports\myreport.rpt
'
'       txtSelectClause - An SQL where clause without the where.  Must use
'                                  Crystal naming convention for the fields
'           eg  {myview.Field} = 5
'
'       ParamArray - An optional parameter used to pass an array of other information to the report.
'                           Currently it can include
'                               Formulas, Stored Procedure Parameters, and Sorting Criteria
'                           If used it must be in the following format
'                               Type of information - cstr_SPParm, cstr_Formula, or cstr_SortCriteria
'                               Number of elements for that type - integer
'                               cstr_SPParm
'                                   SP Parameter Values in proper order
'                               cstr_Formula
'                                   Crystal formula name
'                                   Crystal formula value (strings in ' ' )
'                               cstr_SortCriteria
'                                   Crystal Field Name (Use X to ignore the field)
'                                   Sort Direction - A or D
'

Public Sub crPreview_Report(txtReportName As String, _
                                            txtSelectClause As String, _
                                            ParamArray avOtherCRParms() As Variant)

On Error GoTo errHandler
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim m As Integer

Dim vParm As Variant

Dim intItemCount As Integer
Dim intParmCount As Integer

'
'   Check if report is already in use
'
    If IsObject(crRpt) Then
       Set crRpt = Nothing
    End If

'
'   Open report
'
    Set crApp = New CRAXDRT.Application

    Set crRpt = crApp.OpenReport(txtReportName, 1)
    crRpt.RecordSelectionFormula = txtSelectClause

'
'   Set flags for CRViewer
'
    crRpt.MorePrintEngineErrorMessages = False
    crRpt.EnableParameterPrompting = False
    crRpt.DiscardSavedData

'
'   Determine size of Paramarray
'
    intParmCount = 0
    For Each vParm In avOtherCRParms
        intParmCount = intParmCount + 1
    Next vParm

'
'    Pass other parameters
'
    i = 0
    While (i < intParmCount)
        If (avOtherCRParms(i) = cstr_SPParm) Then
            i = i + 1
            intItemCount = avOtherCRParms(i)
            i = i + 1
            For j = 1 To intItemCount
                For k = 1 To crRpt.ParameterFields.Count
                    If (UCase$(crRpt.ParameterFields(k).Name) = UCase$(avOtherCRParms(i))) Then
                        i = i + 1
                        crRpt.ParameterFields(k).AddCurrentValue avOtherCRParms(i)
                        i = i + 1
                        Exit For
                    End If
                Next k
            Next j
        ElseIf (avOtherCRParms(i) = cstr_Formula) Then
            i = i + 1
            intItemCount = avOtherCRParms(i)
            For j = 1 To intItemCount
                i = i + 1
                For k = 1 To crRpt.FormulaFields.Count
                    If (UCase$(crRpt.FormulaFields(k).Name) = UCase$(avOtherCRParms(i))) Then
                        i = i + 1
                        crRpt.FormulaFields(k).Text = avOtherCRParms(i)
                        Exit For
                    End If
                Next k
            Next j
        ElseIf (avOtherCRParms(i) = cstr_SortCriteria) Then
            i = i + 1
            intItemCount = avOtherCRParms(i)
            i = i + 1
            For j = 1 To intItemCount
                For k = 1 To crRpt.Database.Tables.Count
                    If (avOtherCRParms(i) = "X") Then
                        i = i + 2
                    Else
                        For m = 1 To crRpt.Database.Tables(k).Fields.Count
                            If (UCase$(crRpt.Database.Tables(k).Fields(m).Name) = _
                                                                                UCase$(avOtherCRParms(i))) Then
                                crRpt.RecordSortFields(j).Field = crRpt.Database.Tables(k).Fields(m)
                                i = i + 1
                                If (avOtherCRParms(i) = "A") Then
                                    crRpt.RecordSortFields(j).SortDirection = crAscendingOrder
                                Else
                                    crRpt.RecordSortFields(j).SortDirection = crDescendingOrder
                                End If
                                i = i + 1
                                Exit For
                            End If
                        Next m
                    End If
                Next k
            Next j
        End If
        i = i + 1
    Wend

'
' Set the viewer's report source to the Report object
'
    Me.rptCRViewer.ReportSource = crRpt
    Me.rptCRViewer.ViewReport
    Me.Show

    Exit Sub

errHandler:
    LogErrors Err.Number, Err.Description, Me.Name, "crPreview_Report()"
    Resume Next

End Sub

mlmcc
0
 
LVL 10

Expert Comment

by:ebolek
ID: 12587013
ref ReportDocument report:This is the report document object that you have to pass to the function
 string ParameterName: this is the parameter name used by the report for the report,
object value: This is the value of the parameter that you have to set runtime to the parameter passed
Then the function will take care the rest for .Net
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 12847290
May have helped.  Code is useful as a PAQ but maybe just PAQ with no refund.

mlmcc
0
 
LVL 2

Author Comment

by:neele
ID: 12855811
Hi

Actually firstly i yet to have time to look and try the code. Which i suppose is for Window Form? Instead of web form. But should be similar i guess?

Secondly my question actually is more toward how to segregate the parameter fields, as in ONE report can have input such as DATE/CUSTOMER ID/PRODUCT CODE another might be DATE/ID no/AGE etc..And there are more than 20 reports. So how to display the parameter page well?? By seperating into different web formsss by grouping all similar parameter or??? >> This seem yet to be answer. Maybe i din explain well...Oppss..

That mainly why i yet to accept an answer. Can i accept an answer later? >> 
Thanks !
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 12864168
Sure but you need to keep the dialog going.  Even if it a comment that you haven't had time to try the suggestions.

The code provided is for VB6.

As to how to enter the data, it could be on one form with the appropriate fields made visible or use several forms.

mlmcc
0
 
LVL 2

Author Comment

by:neele
ID: 12866825
Haha okok..will try to reply..As i have been busy trying other stuff so yet to get time to test this. BTW can i just ask a ADD on ques?  Is it necessary to ALWAYS apply DB logon info to Crystal Report??

**Hmm maybe i should accept answer n test later?

thanks :)
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 12873397
>> Is it necessary to ALWAYS apply DB logon info to Crystal Report??
From experience no.  As a caveat, the database and report must be setup correctly.

We have a MS SQL database and use Windows login permissions to control access therefore there is no login for the users.  The reports are setup as trusted connections so again no login information is needed.  Users do not have the tools necessary to access the database in any other manner.  It is on its own server and we are the administrators.  

We alos were able to build our small developer network to mimic the production network (since it is totally separate) to include the server name, mapped drives, directory structures etc.  Thus there is no need to modify reports when we move them from dev to prod.

mlmcc
0
 
LVL 2

Author Comment

by:neele
ID: 12930087
Yet to able to test..guess is better i accept an answer first :)
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 12931378
Glad i could help

mlmcc
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question