I'm making an app to add test questions to a SQL DB. I'm planning on using a Stored procedure to insert the question and then would like to return the Identity so I can use that to do the inserts for the answers into the Answers table. So far I have this as the stored procedure.
Code:
CREATE PROCEDURE sp_AddQuestion
(
	@question AS VARCHAR (8000),
	@Identity AS INT
)
AS
	INSERT INTO Questions(questions) values(@question)
	RETURN SELECT @@IDENTITY as 'Identity'
GO
and in the form I'm using this code
VB Code:
  1. Private Sub cmdInsert_Click()
  2. Dim objCmd As ADODB.Command
  3. Dim rs As ADODB.Recordset
  4.  
  5.     Set objCmd = New ADODB.Command
  6.     With objCmd
  7.         Set .ActiveConnection = Cn
  8.         .CommandType = adCmdStoredProc
  9.         .CommandText = "sp_AddQuestion"
  10.        
  11.         .Parameters.Append .CreateParameter("@question", adVarChar, adParamInput, 300, "Test question Input")
  12.         .Parameters.Append .CreateParameter("@Identity", adInteger, adParamOutput, 4)
  13.    
  14.         Set rs = .Execute
  15.         MsgBox rs.Fields(0)
  16.     End With
  17. End Sub
When I try to run this I'm getting the following error on the execute line.
Formal parameter ‘@Identity’ was defined as OUTPUT but the actual parameter not declared OUTPUT.
What does this error mean and how can I return the id of the last record entered?