0
votes

have an application written in Visual Basic, .NET 3.5 (VS2008)... and have reports created in Crystal Reports 2008 .... everything works fine... I pass the parameter values with code like this...

Dim SParams as new hashtable
SParams.add(paramname1,paramvalue1)
SParams.add(paramname2,paramvalue2)
SParams.add(paramname3,paramvalue3)
....
For Each Param As ParameterField In rep.ParameterFields
            If SParams.ContainsKey(Param.Name.ToUpper) Then
                rep.SetParameterValue(Param.Name, SParams(Param.Name.ToUpper))
            Else
                rep.SetParameterValue(Param.Name, Param.DefaultValues())
            End If
Next
... and it works fine...

I want to change some parameter values when report displayed in report viewer at runtime... The user should be able to modify these values. How can I do this? Similar to the Crystal Reports designer preview. From the CR preview is possible change values?

3
What is your data source for the report. Is there a text file that the report is pulling data from, or is it connecting to a database?Dillie-O

3 Answers

1
votes

One approach I've done to solve this issue in the past is to create my own "parameter entry" screen for the user to specify their custom values. Once submitted, the process runs its own custom query and injects the result set into the Crystal Report. The report then simply serves as a presentation mechanism for the data.

What makes this nice is that you can configure the Crystal Report to use the XSD source as its data model, which serves as an empty skeleton of what the data will look like. Then in your code behind for your form you do something as simple as this:

Dim crResults As New ReportDocument
Dim dtReportData As New DataTable

crResults.Load("PathToReport", OpenReportMethod.OpenReportByTempCopy)
dtReportData = RunStoredProcedure(ReportInfo.ProcedureName, ReportInfo.Parameters)
crResults.SetDataSource(dtReportData)

Note: The RunStoredProcedure is a custom function I setup to call a stored procedure and pass in a HashTable of parameters to bind, but you can roll this any way you need to to get the DataTable storing your results.

0
votes

I probably have wrong assigned question.Look... I Have a created crystal Report document (invoice)... this document have many parameters t.e. Name,address,phone,tax rate and other... and have binded to Datatable, which includes information about goods,quantity,cost and other... this all works fine... and this i do with this code.

Dim rptobj As New rpt_Invoice ' my invoice sceleton
Using tblInvoice As New DataTable
'DataTable to bind
tblInvoice.Columns.Add("ANAME", GetType(String))
tblInvoice.Columns.Add("CNT", GetType(Double))
tblInvoice.Columns.Add("CNTSTR", GetType(String))
tblInvoice.Columns.Add("OUT_PR", GetType(Double))
For Each row As Datagridviewrow In rowCol
    Dim Drow As Data.DataRow = tblInvoice.NewRow
    Drow.Item("ANAME") = DBNullBug(row.Cells("ANAME").Value)
    Drow.Item("CNT") = row.Cells("DECCNT").Value
    Drow.Item("CNTSTR") = row.Cells("CNT").Value
    Drow.Item("OUT_PR") = row.Cells("SOLD_PR").Value
    tblInvoice.Rows.Add(Drow)
Next
'Params to pass 
Dim RPTParams As New Hashtable
RPTParams.Add("NDS", OPT.Item.NDSValue)
RPTParams.Add("INVOICENUM", "")
RPTParams.Add("INVOICEHIMQ", "")
RPTParams.Add("KATPASHT1", "Director")
RPTParams.Add("KATPASHT2", "Accountant")
RPTParams.Add("VCHPASHT1", "Director")
RPTParams.Add("VCHPASHT2", "Accountant")
RPTParams.Add("ADATE", CDate(Now))
RPTParams.Add("INFO", "")
RPTParams.Add("ORDER_ID", Order_Id)
Dlg_RepPreview.STable = tblInvoice
Dlg_RepPreview.SParams = RPTParams
Dlg_RepPreview.rep = rptobj
Dlg_RepPreview.ShowDialog()
End Using

And the form called "Dlg_RepPreview" has rep variable (reportdocument) and STable (DataTable),SParams as Hashtable (hashtable with parameters).

on the Form_Load i writen this code

Private Sub Dlg_Rep_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load RP_Viwer.ReportSource = rep ' RP_Viwer is my ReportViewer If STable IsNot Nothing Then rep.SetDataSource(STable) ' setup datasource End If For Each Param As ParameterField In rep.ParameterFields ' set parametervalues If SParams.ContainsKey(Param.Name.ToUpper) Then rep.SetParameterValue(Param.Name, SParams(Param.Name.ToUpper)) Else rep.SetParameterValue(Param.Name, Param.DefaultValues()) End If Next RP_Viwer.Zoom(75) RP_Viwer.Refresh() End Sub

in this form i have a button. when user clicks on that button, openes the dialog form,with all paramteres and values in report (without datasource).User be able to change parameter values (e.t.c address,phone,name) except datasource (e.t.c goods,quantity,cost). I cant do that. i try code something as simple as this:

rep.SetParameterValue(Param.Name, Param.value)
rep.Refresh()
RP_Viwer.Refresh()

but this code does not work...How i can do ???

0
votes

Thanks for any help...I got an answer... here is the code

Private Sub SetParameters(ByVal Params As Hashtable)
    rep.DataDefinition.ParameterFields.Reset() ' rep is the ReportDocument
    ' rep.Refresh()
    For Each Param As ParameterField In rep.ParameterFields
        If Params.ContainsKey(Param.Name.ToUpper) Then
            rep.SetParameterValue(Param.Name, Params(Param.Name.ToUpper))
        Else
            rep.SetParameterValue(Param.Name, Param.DefaultValues())
        End If
    Next
    SetReport(rep)
End Sub

Public Sub SetReport(ByVal rpt As ReportDocument)
    RP_Viwer.Hide()
    RP_Viwer.ReportSource = rpt
    RP_Viwer.Zoom(75)
    RP_Viwer.Refresh()
    RP_Viwer.ShowLastPage()
    Lbl_TotalPageCount.Text = "/" & RP_Viwer.GetCurrentPageNumber()
    RP_Viwer.ShowFirstPage()
    RP_Viwer.Show()
End Sub