我的vb.net程序存在问题。问题来自我的存储过程类。我已经在我正在使用的SQL数据库中测试了存储过程,并且所有这些都在工作。
我还要注意,我确实将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
这是我正在修复的代码,但它不起作用。我不明白我做错了什么,这让我疯了。我需要第二对(如果不是更多)眼睛。 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
以下是为那些想知道确切措辞的人弹出的错误: Error Message Screen Shot. 如允许,任何帮助表示赞赏。
答案 0 :(得分:0)
set nocount on
你的杂货店里有什么?我猜ExecuteNonQuery无法返回受影响的行数...
答案 1 :(得分:0)
主管查看我的代码以提供帮助。意识到它应该是Excute Reader而不是ExecuteNonQuery。我正在寻找信息,而不是插入新的资源。
感谢您的帮助!