Subscribe to Subscribers
Talk to Webmaster Tony John

Forums » .NET » ASP.NET »

How to avoid similar Column values in SQL DB?


Posted Date: 23 Nov 2009      Posted By:: DoubtTgr     Member Level: Silver    Member Rank: 1024     Points: 1   Responses: 6



Hai,
I have a sql login Database withe fields like Username,passwrd and email. new user getting register with existing username. i need to avoid this useing C#. how can i do this.
C3 sample.

Thanx in Advance.

Thanks in Advance
DoubtTgr




Responses

#446121    Author: Praveen      Member Level: Gold      Member Rank: 70     Date: 23/Nov/2009   Rating: 4 out of 54 out of 54 out of 54 out of 5     Points: 6

hi,

give primary key or unique key to user name column



 
#446122    Author: DoubtTgr      Member Level: Silver      Member Rank: 1024     Date: 23/Nov/2009   Rating: 2 out of 52 out of 5     Points: 2

ya i find the same solution. grt.

Thanks in Advance
DoubtTgr



 
#446123    Author: Alwyn Duraisingh        Member Level: Gold      Member Rank: 11     Date: 23/Nov/2009   Rating: 2 out of 52 out of 5     Points: 2

In the Sql Procedure you can handle this.

Declare @UserName VARCHAR(50),
@Msg VARCHAR(100)
IF NOT EXISTS(Select UserName From table Where UserName = @UserName)
BEGIN
INSER INTO table values(username,Password)
END
ELSE
BEGIN
SET @Msg = 'UserName already available'
Return
END


Regards,
Alwyn Duraisingh.M 
<< Database Administrator >>
Jesus saves! The rest of us better make backups...






 
#446133    Author: Avinash Mohan      Member Level: Gold      Member Rank: 258     Date: 23/Nov/2009   Rating: 2 out of 52 out of 5     Points: 2

Just Include and Identity column in your table and keep that column as the primary key

Thanks and Regards
Avinash Mohan M.R
http://amicably.ning.com



 
#446161    Author: Manindra Kumar Upadhyay      Member Level: Gold      Member Rank: 185     Date: 23/Nov/2009   Rating: 2 out of 52 out of 5     Points: 2

if you use .Net 3.5 then use linq to avoid this else
Use above examples.



 
#446181    Author: Asheej T K        Member Level: Diamond      Member Rank: 2     Date: 23/Nov/2009   Rating: 2 out of 52 out of 5     Points: 2

Use below stored procedure. Check the return value from your code and display message accordingly,


CREATE PROCEDURE sp_NewUser
(
@UserId char(10),
@Password char(10),
@Privilege numeric(18,0),
@MessageCode INT OUTPUT
)
AS
BEGIN
IF EXISTS(SELECT * FROM tbl_Login where UserId=@UserId)
begin
SET @MessageCode = -1
return
end
INSERT INTO [tbl_Login]([UserId], [Password], [Privilege])
VALUES(@UserId, @Password,@Privilege)
if @@ERROR<>0
BEGIN
SET @MessageCode =1
END
ELSE
SET @MessageCode =0
SET NOCOUNT OFF
END



Regards,
Asheej T K
Microsoft MVP[ASP.NET/IIS]
DotNetSpider MVM

Dotnet Galaxy



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Vs 2005
Previous : How to change the text Login to Logout afteruser login?
Return to Discussion Forum
Post New Message
Category:

Related Messages
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.