Question

I'm having an issue with my vb.net program. The issue is coming from my stored procedure classes. I have tested the stored procedures in the SQL database I'm working with, and all of them are working.

I also want to note that I did copy and paste the SP's name over to the SQL server and executed it and it ran perfectly.

EXEC dbo.ksp_Get_Available_Statuses

In the program itself only one SP class is working. The following is that code:

Imports System.Data.SqlClient

Public Class Add_Term
    Public Function addTerm(ByVal term As String, ByVal definitionSource As Integer, ByVal formatNote As String, ByVal definition As String, ByVal authorization As String, ByVal addReason As String)
        Dim connection As SqlConnection = DataConnection.getProperityDBConnection

        Dim insertCommand As New SqlCommand("dbo.ksp_Add_Term", connection)
        insertCommand.CommandType = CommandType.StoredProcedure
        insertCommand.Parameters.AddWithValue("@term", term)
        insertCommand.Parameters.AddWithValue("@definitionSource", definitionSource)
        insertCommand.Parameters.AddWithValue("@formatNote", formatNote)
        insertCommand.Parameters.AddWithValue("@definition", definition)
        insertCommand.Parameters.AddWithValue("@authorization", authorization)
        insertCommand.Parameters.AddWithValue("@addReason", addReason)

    Try
        connection.Open()
        Dim count As Integer = insertCommand.ExecuteNonQuery()
        If count > 0 Then
            Return True
        Else
            Return False
        End If
    Catch ex As Exception
        Throw ex
    Finally
        connection.Close()
    End Try
 End Function
End Class

Here is the code I'm working on fixing, but it's not working. I don't see what I'm doing wrong and it's driving me nuts. I need a second pair (if not more) eyes on it. Imports System.Data.SqlClient

Public Class Get_Avaliable_Statuses
    Public Function getAvailableStatuses()
        Dim connection As SqlConnection = DataConnection.getProperityDBConnection

        Dim insertCommand As New SqlCommand("dbo.ksp_Get_Available_Statuses", connection)
        insertCommand.CommandType = CommandType.StoredProcedure

        Try
            connection.Open()
            Dim count As Integer = insertCommand.ExecuteNonQuery()
            If count > 0 Then
                Return True
            Else
                Return False
            End If
        Catch e As Exception
            Throw e
        Finally
            connection.Close()
        End Try
    End Function
End Class

The following is the error that is popping up for those that want to know the exact wording: Error Message Screen Shot. As allows, any help is appreciated.

Was it helpful?

Solution 2

Supervisor looked over my code to assist. Realized it should be Excute Reader and not ExecuteNonQuery. I'm looking for information, not inserting new sources.

Thanks for the help!

OTHER TIPS

do you have a

set nocount on

in your sproc? I guess ExecuteNonQuery cannot return the number of affected rows then ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top