Well other than this is NOT a java forum, this is for c# and theres a .net web forum too.. The first thing is that you would have to use some form of ajax type thing as you would need to ask the db if the usernames there - but best advice, ask in a more apprioriate forum.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
I think he crosses 3 forums with this question since he didn't ask a specific question (c#, asp.net, sql).
BUT since you have the mechanism down to execute a query, I don't think its c#. Since you have the page designed, I don't think its asp.net. That leaves SQL (and how you deal with it in c#).
Assuming you're using MSSQL you can do something like (I don't have a compiler with me, so this hasn't been checked for compilation issues):
try
{
query = "Insert into Newuser Select @UserName,@Password,@FullName Where Not Exists (Select * From NewUser x Where x.[UserNameColumn] = @UserName) Select Cast(@@ROWCOUNT as int) As Result";
cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@UserName", txtUsername.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@FullName", txtFullname.Text);
conn.Open();
int rowCnt = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close ();
}
catch(Exception ex)
{
lblErrors.Text =ex.Message.ToString();
}
If the rowcount returns 0 then the username existed, if it returns 1 then you know it didn't. As a recommendation for best practices you should specify the columns in your Insert Into() statement since they're likely to change over time, which could break your query.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735