Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Checking entries & password generation


Message #1 by "Peter Rooney" <peter@w...> on Sat, 6 Apr 2002 13:29:38
Hi I am using a password generation function to generate a random three 
letter password, I then want to check the database to see if the password 
exists if not then add it otherwise generate another one and add that, 
below is the code I wrote thinking it was the logical way to do it, the 
problem is that the code is generated and entered but it then the IF 
staement causes a 'Item cannot be found in the collection corresponding to 
the requested name or ordinal' error.

Below is both the stored procedure and the asp page, can you see what the 
problem is or maybe suggest a better way to acheive it?

Many thanks


===============Stored Procedure=========================

CREATE PROCEDURE dbo.ADD_REGIMENT

	@REGIMENT NVARCHAR(255),
	@REG NVARCHAR(3)


AS
SET NOCOUNT ON

IF EXISTS(SELECT 'True' From tblDETAILS  WHERE Reg = @REG)

BEGIN
	
	 SELECT 'REG EXISTS'

END
ELSE
BEGIN

   INSERT tblDETAILS
(
	Service,
	Reg
	
)
   VALUES 
(
	@REGIMENT ,
	@REG
)


END







===============ASP Page===================================


szSQL="EXEC dbo.ADD_REGIMENT" &_
 " @REGIMENT = '" & SERVICEONEA & "' ,"&_
 " @REG = '" & UCase(generatepassword(False)) & "'"
	
objRS = objConn.Execute(szSQL)

 If objRS(0) = "REG EXISTS" Then 

  szSQL="EXEC dbo.ADD_REGIMENT" &_
  " @REGIMENT = '" & SERVICEONEA & "' ,"&_
  " @REG = '" & UCase(generatepassword(False)) & "'"

  End If

==============================================================

  Return to Index