I'm having a problem with an action stored procedure. It seems to fail to insert data.
Here is the sp:
CREATE PROCEDURE dbo.Stats_SearchTerm_Insert
@ID int OUTPUT,
@SearchTerm varchar(500)
AS
select @ID = ID from Stats_SearchTerm where SearchTerm = @SearchTerm
if @ID is null
begin
insert into Stats_SearchTerm(SearchTerm) values(@SearchTerm)
select @ID = SCOPE_IDENTITY()
end
I've tested it in SQL Server and it works fine, for example the following inserts the data and returns the appropriate ID.
DECLARE @pID int
declare @pSearchTerm varchar(500)
set @pSearchTerm = 'what a wonderful world test'
exec Stats_SearchTerm_Insert @ID = @pID OUTPUT, @SearchTerm = @pSearchTerm
When I run this code it just doesn't insert the data - no errors and no return identity.
Dim SearchTermID As Integer = 0
Dim SearchTerm1 As String = "what a wonderful world"
Dim adapter2 As New DataAccessAdapter
ActionProcedures.Stats_SearchTerm_Insert(SearchTerm1, SearchTermID, adapter2)
adapter2.CloseConnection()
Nada.
The strangest thing is that it does work and returns an ID value if the @pSearchTerm exists in the database. In that case it works fine - it returns the existing ID byref as it should?
How can it be that this code works for existing values but not for inserts?
Any ideas?