[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

Ouput Parameter conversion


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

  • 2
  • 2
1 Solution
Praveen KumarArchitectCommented:
there so no return type in your function
Public Shared Function AddMaster(ByVal item As CupMaster)

Or did i missed other then that?
ALawrence007Author Commented:
I changed that to:
Public Shared Function AddMaster(ByVal item As CupMaster) As Integer
and I still get the same error.
Praveen KumarArchitectCommented:
i am not sure but try to parse to Int32 before u return from function.

 Return Convert.ToInt32( CupDetailsParam("@CupTableID").Value)
ALawrence007Author Commented:
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now