Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Re: Stored Procedur

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-03-31 : 08:45:04
Ali writes "Dear Friends

I am very amator in sql, i try to write an email system with asp.net, i invoke my stored procedure and send username i just want to check username already exist

if my user name already exist ( it is primary key) i don't want to get system error like :

Violation of PRIMARY KEY constraint 'PK_register'. Cannot insert duplicate key in object 'users'

i just want to recieve a number or boolean from stored procedure

there is my stored procedure: but it still i get System error



CREATE PROCEDURE AF_addUser
@uname varchar(255),
@pass varchar (50),
@fname varchar (50),
@lname varchar (50),
@cemail varchar (300),
@language varchar (50),
@address varchar (150),
@zip varchar (6)

AS

if not exists (select uname from users where uname = @uname and pass=@pass )

begin

INSERT INTO USERS(uname, pass, fname, lname, cemail, language, address, zip)
VALUES(@uname , @pass ,@fname ,@lname, @cemail ,@language ,@address ,@zip)

return 1
end
else
return 0
GO"

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-03-31 : 08:55:13
Is only the user name the primary key?

If it is you might be getting the error because the user is inserting an existing username with a different password. You should maybe take out the "and pass = @pass" bit then.


Duane.
Go to Top of Page
   

- Advertisement -