Ouput Parameter conversion

Posted on 2007-10-17
Last Modified: 2010-04-23

I have a SQL based winforms application. This application adds items to a Master table as well as a details table. I need to get the output parameter from my Stored proc (the scope_Identity) to insert into my details table. I get the following error currently:
Conversion from string "@CupTableID" to type 'Integer' is not valid

Here are all my code this far:
Public Shared Function AddMaster(ByVal item As CupMaster)
        Dim objSql As New SQL()
        Dim CupDetailsParam(2) As SqlParameter
        CupDetailsParam(0) = New SqlParameter("@CustomerID", SqlDbType.Int)
        CupDetailsParam(0).Value = item.CustomerID
        CupDetailsParam(1) = New SqlParameter("@CupTotal", SqlDbType.Int)
        CupDetailsParam(1).Value = item.CupTotal
        CupDetailsParam(2) = New SqlParameter("@CupTableID", SqlDbType.Int)
        CupDetailsParam(2).Direction = ParameterDirection.Output
        CupDetailsParam(2).Value = item.CupTableID
        objSql.ExecuteNonQuery("CupMaster", CupDetailsParam)
        Return CupDetailsParam("@CupTableID").Value
    End Function

My Class:
Public Class CupMaster
    Private IntCustomerID As Integer
    Private DecCupTotal As Decimal
    Private IntCupTableID As Integer
    Public Property CupTableID() As Integer
            Return IntCupTableID
        End Get
        Set(ByVal value As Integer)
            IntCupTableID = value
        End Set
    End Property
    Public Property CustomerID() As Integer
            Return IntCustomerID
        End Get
        Set(ByVal value As Integer)
            IntCustomerID = value
        End Set
    End Property
    Public Property CupTotal() As Decimal
            Return DecCupTotal
        End Get
        Set(ByVal value As Decimal)
            DecCupTotal = value
        End Set
    End Property
End Class

My button_Click calls:
Private Function TestingOutput()
        Dim New_ID As String
        Dim Item As New CupMaster
        Item.CustomerID = ACBox.SelectedValue
        Item.CupTotal = ctTBox.Text
        New_ID = Cup.AddMaster(Item)
        Item.CupTableID = New_ID
        Return New_ID
    End Function

Question by:ALawrence007
    LVL 12

    Expert Comment

    there so no return type in your function
    Public Shared Function AddMaster(ByVal item As CupMaster)

    Or did i missed other then that?

    Author Comment

    I changed that to:
    Public Shared Function AddMaster(ByVal item As CupMaster) As Integer
    and I still get the same error.
    LVL 12

    Accepted Solution

    i am not sure but try to parse to Int32 before u return from function.

     Return Convert.ToInt32( CupDetailsParam("@CupTableID").Value)

    Author Comment

    Same Error.
    I don't know where to look anymore.
    Here is my SQL Helper, Maybe this is the issue:
    Public Function ExecuteNonQuery(ByVal query As String, ByVal ParamArray parameters() As SqlParameter) As Integer
            Dim cnn As SqlConnection = New SqlConnection(Conn)
            Dim cmd As SqlCommand = New SqlCommand(query, cnn)
            If query.StartsWith("INSERT") Or query.StartsWith("insert") Or query.StartsWith("UPDATE") Or query.StartsWith("update") Or query.StartsWith("DELETE") Or query.StartsWith("delete") Then
                cmd.CommandType = CommandType.Text
                cmd.CommandType = CommandType.StoredProcedure
            End If
            Dim i As Integer
            For i = 0 To parameters.Length - 1
            Dim retval As Integer = cmd.ExecuteNonQuery()
            Return retval
        End Function

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now