Print Page | Close Window

problem and error in my code pass parameter

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=15734
Printed Date: 03 May 2025 at 8:26pm


Topic: problem and error in my code pass parameter
Posted By: flodi
Subject: problem and error in my code pass parameter
Date Posted: 27 Feb 2012 at 9:57pm
hi
am doing program in vb.net 2010 with sql serevr 2008 and i would like to pass a parameter to my crystal report to print a two related table and make an invoic print
here is my code

Private Sub CmdSearchNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSearchNo.Click
        Try
            Dim em1 As String = InputBox("Enter inv_no?")
            Dim conn As SqlConnection
            conn = New SqlClient.SqlConnection
            conn.ConnectionString = "Data Source=dell-dsl\sqlexpress;Initial Catalog=STOCK;Integrated Security=True"
            conn.Open()
            Dim cmm As SqlCommand
            cmm = New SqlClient.SqlCommand
            cmm.Connection = conn
            cmm.CommandText = "select * from INVHEADOUT where inv_no= '" & Trim(em1) & "' "
            cmm.CommandType = CommandType.Text
            Dim read As SqlClient.SqlDataReader
            read = cmm.ExecuteReader
            If Not read.Read Then
                MsgBox("inv_no not found")
                read.Close()
                conn.Close()
            Else
                Dim pram As New ParameterFields
                Dim para As SqlParameter
                para = New SqlParameter("@pinv_no", SqlDbType.SmallInt)
                para.Value = em1
                Dim par As New ParameterField
                par.ParameterFieldName.Equals("@pinv_no")
                par.CurrentValues.Add(para)
                pram.Add(par)
                CrystalReportViewer1.ParameterFieldInfo = pram
                CrystalReportViewer1.Visible = True
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

its under my print button and the error message is ( invalide object type ) in the line
par.CurrentValues.Add(para)

any suggestion or help?
thx



Print Page | Close Window