C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

sqlserver 2005


Posted Date: 01 Oct 2008      Posted By: subhashini      Member Level: Bronze     Points: 1   Responses: 3



sorry sorry

Iam creating an login form and i'm having 2 buttons in it,and i have created an table in sqlserver 2005.If i insert an user name an password it is getting inserted in data base. Now I wanted the code for if the user name and password already exists a message box should display user name and password already exists and it should not get inserted in database..?
pls help






Responses

Author: Shankar Suresh    01 Oct 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

you have to check if exist condition in your query........
to try like this sp........

Create Proc SPR_Bankmaster_Save

@BankID nvarchar(50),
@BankName nvarchar(50)

as
if exists(select BankID from tbl_Bankmaster where BankID=@BankID)
return 1
else
insert into tbl_Bankmaster
(
BankID,
BankName
)

values
(
@BankID,
@BankName
)


GO



Author: Prafulla S Shimpi    01 Oct 2008Member Level: GoldRating: 5 out of 55 out of 55 out of 55 out of 55 out of 5     Points: 15

Subhishini,

first of all, no need to say sorry.
everybody post here to get answer for their queries and site is dedicated to share the knowledge and find the solutions to their problem.

Now, answer to you queston:

1. UserName must be unique (probably PRIMARY Key field in database)
2. when user enters his details (at the time of sign up) i.e. on click of CreateUser Button click, you need to check whethher any user with this username already exists in database or not?
If not, then allow to create new record, otherwise show an alert to the user
'UserName already exits' .
Password could be same for two different user, you should not restrict the user for the same.

You can write the a small function to check whether UserName is already exists or Not.

If this function returns TRUE, then show alert and stop there, otherwise go ahead with Creating new User.


Private Function FnCheckUserExists(ByVal strUserName As String) As Boolean

Try

string strConn= //write the connectionstring
string strSQL = "Select * from UserMaint where UserName = ' " & strUserName & "'";
SqlConnection gConn = new SqlConnection(strConn);

SqlDataReader sReader;

using (sReader = new SqlCommand(strSQL , gConn).ExecuteReader
())
{
if (sRader.HasRows)
Return TRUE;
else
Return FALSE;

}
Catch ex As Exception
//Handle exception
End Try

End Function


Hope this will help



Author: subhashini    01 Oct 2008Member Level: BronzeRating: 1 out of 5     Points: 1

thank you


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 : sqlserver 2005
Previous : how to close an opened excel file in vb
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use