Link to home
Start Free TrialLog in
Avatar of Ilianam
Ilianam

asked on

What is going on here? It was working and now it fails

Dim mycommand = New SqlClient.SqlCommand("spMdViewClaimdetail", myConnection)
        Dim adapter As New SqlClient.SqlDataAdapter(mycommand)
        Dim ds As New DataSet()
        Dim crpt As New CrystalReport1()
        Dim crpt2 As New CrystalReport2()
        'new
        Dim crParameterfieldDefinitions As ParameterFieldDefinitions
        Dim crParameterfieldDefinition As ParameterFieldDefinition
        Dim crParameterValue As New ParameterValues()
        Dim crparameterdiscreteValue As New ParameterDiscreteValue()

        '  Dim Report As New ViewReports()
        Dim rptCollection As New CrystalDecisions.Shared.ParameterValues()
        Dim pdvClaim As New CrystalDecisions.Shared.ParameterDiscreteValue()
        Dim crvparameter As New CrystalDecisions.Windows.Forms.CrystalReportViewer()
        Try
            If (myConnection.State = ConnectionState.Closed) Then
                myConnection.open()
            End If

            With mycommand
                .CommandTimeout = 1000
                .CommandType = CommandType.StoredProcedure
                .Parameters.Add("@Claimno", SqlDbType.BigInt)
                .Parameters("@Claimno").Value = denial
                .ExecuteNonQuery()
            End With

            adapter.Fill(ds)

            ds.Tables(0).TableName = "spMDViewDenials"
            If ds.Tables(0).Rows(0).Item(9) = "I" Or ds.Tables(0).Rows(0).Item(9) = "IP" Then
                inout = True
                crpt.SetDataSource(ds)
            End If
            If ds.Tables(0).Rows(0).Item(9) = "O" Or ds.Tables(0).Rows(0).Item(9) = "OP" Then
                inout = False
                crpt2.SetDataSource(ds)
            End If


            ' Set the discreet value to the customers name.
            pdvClaim.Value = denial

            'Add it to the parameter collection.
            rptCollection.Add(pdvClaim)

            'Apply the current parameter values.
            If inout = True Then
                crpt.DataDefinition.ParameterFields("@Claimno").ApplyCurrentValues(rptCollection)
            Else
                crpt2.DataDefinition.ParameterFields("@Claimno").ApplyCurrentValues(rptCollection)
            End If
            crpt.DataDefinition.ParameterFields("@Claimno").ApplyCurrentValues(rptCollection)

            'Hide group tree for this report
            crvparameter.DisplayGroupTree = False

            '  Set the report source for the crystal reports viewer to the
            ' report instance.
            If inout = True Then
                crvparameter.ReportSource = crpt
            Else
                crvparameter.ReportSource = crpt2
            End If

            ' new

            'crparameterdiscreteValue.Value = denial
            'crParameterfieldDefinitions = crpt.DataDefinition.ParameterFields
            'crParameterfieldDefinition = crParameterfieldDefinitions.Item("@Claimno")
            'crParameterValue.Clear()
            'crParameterValue.Add(crparameterdiscreteValue)

            'crParameterfieldDefinition.ApplyCurrentValues(crParameterValue)


            ds.Tables(0).TableName = "spMDViewDenials"
            If inout = True Then
                crpt.SetDataSource(ds)
            Else
                crpt2.SetDataSource(ds)
            End If

            Dim viewer As New Viewer()

            'If inout = True Then
            '    viewer.CrystalReportViewer2.ReportSource = crpt
            'Else
            '    viewer.CrystalReportViewer2.ReportSource = crpt2
            'End If
            If now = False Then
                viewer.Show()
            Else
                If inout = True Then
                    crpt.PrintToPrinter(1, False, 0, 0)
                Else
                    crpt2.PrintToPrinter(1, False, 0, 0)
                End If
            End If

            myConnection.Close()
        Catch ex As Exception
            MsgBox("Exception: " & ex.Message & "  " & ex.ToString, MsgBoxStyle.Critical)
        End Try
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Hi Ilianam,

And the problem/error/exception is ?

Cheers!
Avatar of Ilianam
Ilianam

ASKER

the error starts here
 If inout = True Then
                crpt.DataDefinition.ParameterFields("@Claimno").ApplyCurrentValues(rptCollection)
            Else
                crpt2.DataDefinition.ParameterFields("@Claimno").ApplyCurrentValues(rptCollection)
            End If

The error says: Invalid Field Name. CrystalDecisions.CrystalReports.Engine.InvalidArgumentException: Invalid field name......
And the $100 question : Are you sure your parameter exist? No typo error?
Avatar of Ilianam

ASKER

The funny part, is that it was working 100%. I move it to another box and gave me another error
Same version of CR?
Are you sure that you have the latest/correct version of CrystalReport1 and CrystalReport2 ? Do you see the parameter if you open the reports in the designer?
Avatar of Ilianam

ASKER

checked, now is asking for the database connection......
The designer or the runtime?
Avatar of Ilianam

ASKER

the runtime
Avatar of Ilianam

ASKER

also, the famous list of fields on the right has disappeared   :(
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are you using Visual Studio?  If so you want to delete the .rpt file from your VS Project (make a backup copy first).  In your project folder, delete the vb file associated with the report (e.g.: report1.vb).  Now put your backup copy of the .rpt into the folder and add the report to your project.  VS will regenerate the .vb file and your binding should work now.

frodoman
Avatar of Ilianam

ASKER

Got a new error.
Failed to open a rowset
That error typically means that there is an error related to the db.  It looks like you're using a stored procedure so my first guess would be that you aren't passing all of the parameters or perhaps not the right type of parameter values.  Could also be that the values you're passing are causing an error in your proc - you might want to execute it with the same params and make sure it works - also display the param values in your application to make sure you're passing what you think you're passing.

frodoman
Avatar of Ilianam

ASKER

It's killing me. I fixed the previous issue. Again, I move it to the test box, its requesting the database userid and password