Monday, 3 November 2014

How to return a single Value from a Stored Procedure

 
 
 
 
I need to return a single value from a stored procedure, after a lot of digging i came up with this all the other ways
 i found did not work.
 
 
 
 
Dim result as integer
  Dim sql As String
        Dim mycomman1 As New SqlCommand
        Try
            mycomman1.Connection = sqlCon  'Set your connection
            mycomman1.CommandType = CommandType.StoredProcedure
            mycomman1.CommandText = "Getproductid"  'Name of Stored Procedure
            With mycomman1
                .Parameters.Add("@product_code"SqlDbType.VarChar, ParameterDirection.Input).Value = productcode
                .Parameters.Add("@description"SqlDbType.VarChar, ParameterDirection.Input).Value = delimitedtext(25)
                .Parameters.Add("@Customer"SqlDbType.Int, ParameterDirection.Input).Value = 199
            End With
        Catch ex As Exception
 
        End Try 
'create a table to store result
         Dim dt As New DataTable
        Dim da = New SqlDataAdapter(mycomman1)
        Dim ds As New DataSet()
        da.Fill(dt)
 
        If dt.Rows.Count > 0 Then
            tstr = dt.Rows(0)("return status").ToString
            Result = CInt(tstr) --------  
        End If
 
        da.Dispose() 
        sqlCon1.Close()

No comments:

Post a Comment

Chrome 138 the last supported

Chrome 138 the last supported  Hey Everyone, Chrome 138 is the last version of Chrome that will support Android 8.0 (Oreo) and Android 9.0 (...