我有我的vb.net程序的问题。问题来自我的存储过程类。我测试了我正在使用的SQL数据库中的存储过程,并且它们都在工作。存储过程返回FALSE在vb.net
我也想指出,我没有复制和粘贴SP的名字到SQL服务器并执行它,它完美地运行。
EXEC dbo.ksp_Get_Available_Statuses
在程序本身中,只有一个SP类正在工作。以下是代码:
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
这里是我工作的固定代码,但它不工作。我没有看到我做错了什么,这让我很疯狂。我需要第二对(如果不是更多)的眼睛。 进口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
以下是雨后春笋般冒出来为那些想知道确切的写法错误: Error Message Screen Shot. 作为允许,任何帮助表示赞赏。
你确定这两个特效都是在同一个数据库。检查[this](http://stackoverflow.com/questions/847879/could-not-find-stored-procedure)。 – user2989408
是的。两个SP都使用相同的数据连接类。他们都在SQL服务器上工作,但只有其中一个在代码中工作。我不知道为什么它不断返回第二个SP为假。它有结果的行。 – Gnathan