I am having trouble getting the return values on my stored procedure working in VB using ADO. Currently I have...
---- Start VB Code
Public Function EmployeeSelectByID(intID As Integer)
As Recordset
On Error GoTo Err_EmployeeSelectByID
'Use the global ADO command object.
Set g_objCmd = New ADODB.Command
'Setup the command object.
Set g_objCmd.ActiveConnection = g_objConn
g_objCmd.CommandText = "procEmployeeSelectByID"
g_objCmd.CommandType = adCmdStoredProc
'Append the parameters into the command object.
g_objCmd.Parameters.Append
g_objCmd.CreateParameter("Return", adInteger, _
adParamReturnValue)
g_objCmd.Parameters.Append
g_objCmd.CreateParameter("EmployeeID", adInteger, _
adParamInput, , intID)
'Now execute our command and return recordset result.
Set EmployeeSelectByID = g_objCmd.Execute
MsgBox "Return: " & g_objCmd.Parameters("Return"
Exit_EmployeeSelectByID:
'Remove references to objects.
Set g_objCmd = Nothing
Exit Function
Err_EmployeeSelectByID:
LogError "modRead.EmployeeSelectByID()"
End Function
---- End Code
My stored procedure looks like this..
---- Start Stored Procedure
CREATE PROCEDURE procEmployeeSelectByID
@EmployeeID as int
AS
--Declare the output variable
DECLARE @Return int
--Get all the records
SELECT * FROM tblEmployee
WHERE EmployeeID = @EmployeeID
--Get the RecordCount so we can return it to the application
SELECT @Return = @@rowcount
--Look for errors
IF @@error > 0
SELECT @Return = -1
RETURN @Return
GO
---- End Stored Procedure
My problem is that the return value is coming back as "". Does anyone see any errors in the code that would cause this?
---- Start VB Code
Public Function EmployeeSelectByID(intID As Integer)
As Recordset
On Error GoTo Err_EmployeeSelectByID
'Use the global ADO command object.
Set g_objCmd = New ADODB.Command
'Setup the command object.
Set g_objCmd.ActiveConnection = g_objConn
g_objCmd.CommandText = "procEmployeeSelectByID"
g_objCmd.CommandType = adCmdStoredProc
'Append the parameters into the command object.
g_objCmd.Parameters.Append
g_objCmd.CreateParameter("Return", adInteger, _
adParamReturnValue)
g_objCmd.Parameters.Append
g_objCmd.CreateParameter("EmployeeID", adInteger, _
adParamInput, , intID)
'Now execute our command and return recordset result.
Set EmployeeSelectByID = g_objCmd.Execute
MsgBox "Return: " & g_objCmd.Parameters("Return"
Exit_EmployeeSelectByID:
'Remove references to objects.
Set g_objCmd = Nothing
Exit Function
Err_EmployeeSelectByID:
LogError "modRead.EmployeeSelectByID()"
End Function
---- End Code
My stored procedure looks like this..
---- Start Stored Procedure
CREATE PROCEDURE procEmployeeSelectByID
@EmployeeID as int
AS
--Declare the output variable
DECLARE @Return int
--Get all the records
SELECT * FROM tblEmployee
WHERE EmployeeID = @EmployeeID
--Get the RecordCount so we can return it to the application
SELECT @Return = @@rowcount
--Look for errors
IF @@error > 0
SELECT @Return = -1
RETURN @Return
GO
---- End Stored Procedure
My problem is that the return value is coming back as "". Does anyone see any errors in the code that would cause this?