vb.net passing parameters

  • Thread starter Thread starter douglas
  • Start date Start date
D

douglas

How should I pass 2 parameters from a vb.net 2005 windows application to a
crystal report that is written in version 11?
I am working on a Visual Basic.NET 2005 windows application. This
application needs to call an existing crystal report written in version 11
and needs to pass two (2) parameters to the crystal report.
When I step though the code I think I am passing the first parameter, and
I know that I am not passing the second parameter. I am getting an error
message on the second when I step though the code.
My code is basically the following (except I do not know how to code the
second parameter)
mports CrystalDecisions.Shared
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Windows.Forms
Imports System.Data.SqlClient

Public Class vbCls

Dim cryRpt As New ReportDocument

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim cryRpt As New ReportDocument
Dim sql As String
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As SqlDataAdapter
Dim ds As New DataSet
Dim i As Integer
'located crystal report from
Dim strReportPath As String = "C:\TstReport.rpt"
connetionString = "Data Source=server3;Initial
Catalog=ProgTest;User ID=xxx;Password=xxxx"
connection = New SqlConnection(connetionString)
sql = "select * from test_table"

Try
connection.Open()
adapter = New SqlDataAdapter(sql, connection)
adapter.Fill(ds)
connection.Close()

cryRpt.Load(strReportPath)

Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue

crParameterDiscreteValue.Value = 12345
crParameterFieldDefinitions = _
cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = _
crParameterFieldDefinitions.Item("@Id")
crParameterValues = crParameterFieldDefinition.CurrentValues

crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()

Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

End Class


The error message I am getting every time I try to code a second parameter
is pass is the following:
crystaldecisions.crystalreports.engine.ParameterFieldCurrentValueException:
Missing parameter values
-->System.Runtime.InteropServices.ComException (0x8004100E): Missing
paramter values.


Thanks!
 
  How should I pass 2 parameters from a  vb.net 2005 windows application to a
crystal report that is written in version 11?
  I am working on a Visual Basic.NET 2005 windows application. This
application needs to call an existing crystal report written in version 11
and needs to pass two (2) parameters to the crystal report.
  When I step though the code I think I am passing the first parameter,and
I know that I am not passing the second parameter. I am getting an error
message on the second when I step though the code.
  My code is basically the following (except I do not know how to code the
second parameter)
mports CrystalDecisions.Shared
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Windows.Forms
Imports System.Data.SqlClient

Public Class vbCls

    Dim cryRpt As New ReportDocument

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument
        Dim sql As String
        Dim connetionString As String
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim ds As New DataSet
        Dim i As Integer
        'located crystal report from
        Dim strReportPath As String = "C:\TstReport.rpt"
                connetionString = "Data Source=server3;Initial
Catalog=ProgTest;User ID=xxx;Password=xxxx"
        connection = New SqlConnection(connetionString)
        sql = "select * from test_table"

        Try
            connection.Open()
            adapter = New SqlDataAdapter(sql, connection)
            adapter.Fill(ds)
            connection.Close()

                cryRpt.Load(strReportPath)

                Dim crParameterFieldDefinitions As ParameterFieldDefinitions
                Dim crParameterFieldDefinition As ParameterFieldDefinition
                Dim crParameterValues As New ParameterValues
                Dim crParameterDiscreteValue As New ParameterDiscreteValue

                crParameterDiscreteValue.Value = 12345
                crParameterFieldDefinitions = _
                cryRpt.DataDefinition.ParameterFields
                crParameterFieldDefinition = _
                crParameterFieldDefinitions.Item("@Id")
                crParameterValues = crParameterFieldDefinition.CurrentValues

                crParameterValues.Clear()
                crParameterValues.Add(crParameterDiscreteValue)

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

                CrystalReportViewer1.ReportSource = cryRpt
                CrystalReportViewer1.Refresh()

                  Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

End Class

  The error message I am getting every time I try to code a second parameter
is pass is the following:
crystaldecisions.crystalreports.engine.ParameterFieldCurrentValueException:
Missing parameter values
 -->System.Runtime.InteropServices.ComException (0x8004100E): Missing
paramter values.

Thanks!

have you tried the SetParameterValue method of the ReportDocument
object?
 
"Appr3nt1c3":

Excellent suggestion!

I have not tried the SetParameterValue method of the ReportDocument object
yet.
I will let you know if this solves the report after I return to work on
Monday.
The code examples that I was basically using was from the following link:
http://vb.net-informations.com/crystal-report/vb.net_crystal_report_parameter_string.htm.
After looking for my error message on the internet, I found that I needed
to pass parameters through the ReportDocument object and not through the
report viewer!

Thanks!
 
"Appr3nt1c3"
Could you display some code in the SetParameterValue method of the
ReportDocument object that has worked for you? If you have not used this
code, could you display some code that you beleive would work?

Thanks!
 
Back
Top