Register a new user
-
hey guys :) pi have an application.. and i wanna add new user to a database but i want to check if the usernameis already exist in the database. how can i do it right ? thanks :)
Estarta
-
hey guys :) pi have an application.. and i wanna add new user to a database but i want to check if the usernameis already exist in the database. how can i do it right ? thanks :)
Estarta
use a sql query to check if the name exists in the DB
Kind Regards, Gary
My Website || My Blog || My Articles
-
use a sql query to check if the name exists in the DB
Kind Regards, Gary
My Website || My Blog || My Articles
Thanks for the reply man.. i have an sql statmenent and its not the problem how can can i handel this when the 'admin' wanna add new user lets say.. when he click 'SUBMIT' it should tells him that the username is in use. i'll show u a sample if u don't mind conn.Open(); cmd = new SqlCommand ("select schoolid from users where userid= " + Session["UserID"],conn); string SchoolID= cmd.ExecuteScalar().ToString(); cmd = new SqlCommand("AddStudent",conn); cmd.CommandType=CommandType.StoredProcedure; SqlParameter Name = new SqlParameter("@Name",this.TextBox5.Text); SqlParameter Username = new SqlParameter("@Username",this.TextBox6.Text); SqlParameter Password = new SqlParameter("@Password",this.TextBox7.Text); SqlParameter School = new SqlParameter("@SchoolID",SchoolID); SqlParameter ParentID = new SqlParameter("@ParentID",ParentDWL.SelectedItem.Value.ToString()); SqlParameter Address = new SqlParameter("@Address",this.TextBox9.Text); SqlParameter LevelID = new SqlParameter("@LevelID",int.Parse(this.DropDownList2.SelectedItem.Value)); cmd.Parameters.Add(Name); cmd.Parameters.Add(Username); cmd.Parameters.Add(Password); cmd.Parameters.Add(School); cmd.Parameters.Add(ParentID); cmd.Parameters.Add(Address); cmd.Parameters.Add(LevelID); int i=cmd.ExecuteNonQuery(); Estarta
-
Thanks for the reply man.. i have an sql statmenent and its not the problem how can can i handel this when the 'admin' wanna add new user lets say.. when he click 'SUBMIT' it should tells him that the username is in use. i'll show u a sample if u don't mind conn.Open(); cmd = new SqlCommand ("select schoolid from users where userid= " + Session["UserID"],conn); string SchoolID= cmd.ExecuteScalar().ToString(); cmd = new SqlCommand("AddStudent",conn); cmd.CommandType=CommandType.StoredProcedure; SqlParameter Name = new SqlParameter("@Name",this.TextBox5.Text); SqlParameter Username = new SqlParameter("@Username",this.TextBox6.Text); SqlParameter Password = new SqlParameter("@Password",this.TextBox7.Text); SqlParameter School = new SqlParameter("@SchoolID",SchoolID); SqlParameter ParentID = new SqlParameter("@ParentID",ParentDWL.SelectedItem.Value.ToString()); SqlParameter Address = new SqlParameter("@Address",this.TextBox9.Text); SqlParameter LevelID = new SqlParameter("@LevelID",int.Parse(this.DropDownList2.SelectedItem.Value)); cmd.Parameters.Add(Name); cmd.Parameters.Add(Username); cmd.Parameters.Add(Password); cmd.Parameters.Add(School); cmd.Parameters.Add(ParentID); cmd.Parameters.Add(Address); cmd.Parameters.Add(LevelID); int i=cmd.ExecuteNonQuery(); Estarta
Whats the code like in your AddStudent Stored Procedure ? If you're using a stored proc to do the add it would make sense to do a test in the stored proc if the user name exists, if it does then send a notification back to the application that the user name already exists and that the transaction could not be completed
Kind Regards, Gary
My Website || My Blog || My Articles
-
Whats the code like in your AddStudent Stored Procedure ? If you're using a stored proc to do the add it would make sense to do a test in the stored proc if the user name exists, if it does then send a notification back to the application that the user name already exists and that the transaction could not be completed
Kind Regards, Gary
My Website || My Blog || My Articles
well thats cool i will send you the stored procedure code :) thanks CREATE PROCEDURE AddStudent @Name varchar(20), @Username varchar(20), @Password varchar(20), @SchoolID int, @ParentID int, @Address varchar(20), @LevelID int as insert into users values (3,@Name,@Username,@Password,@SchoolID,@ParentID,@Address,@LevelID,NULL) GO
Estarta
-
well thats cool i will send you the stored procedure code :) thanks CREATE PROCEDURE AddStudent @Name varchar(20), @Username varchar(20), @Password varchar(20), @SchoolID int, @ParentID int, @Address varchar(20), @LevelID int as insert into users values (3,@Name,@Username,@Password,@SchoolID,@ParentID,@Address,@LevelID,NULL) GO
Estarta
CREATE PROCEDURE AddStudent @Name varchar(20), @Username varchar(20), @Password varchar(20), @SchoolID int, @ParentID int, @Address varchar(20), @LevelID int as Declare @ExistUser varchar(20) SELECT @ExistUser = Username from users where username = @username IF(@ExistUser is Null) Begin insert into users values (3,@Name,@Username,@Password,@SchoolID,@ParentID,@Address,@LevelID,NULL) end GO This is something rough for you to use and give you an idea of what to do. You'll have to elaborate a bit more on this
Kind Regards, Gary
My Website || My Blog || My Articles
-
well thats cool i will send you the stored procedure code :) thanks CREATE PROCEDURE AddStudent @Name varchar(20), @Username varchar(20), @Password varchar(20), @SchoolID int, @ParentID int, @Address varchar(20), @LevelID int as insert into users values (3,@Name,@Username,@Password,@SchoolID,@ParentID,@Address,@LevelID,NULL) GO
Estarta
Thanks alot :) i will try it now. Regards
Estarta
-
CREATE PROCEDURE AddStudent @Name varchar(20), @Username varchar(20), @Password varchar(20), @SchoolID int, @ParentID int, @Address varchar(20), @LevelID int as Declare @ExistUser varchar(20) SELECT @ExistUser = Username from users where username = @username IF(@ExistUser is Null) Begin insert into users values (3,@Name,@Username,@Password,@SchoolID,@ParentID,@Address,@LevelID,NULL) end GO This is something rough for you to use and give you an idea of what to do. You'll have to elaborate a bit more on this
Kind Regards, Gary
My Website || My Blog || My Articles
It worked, i dont know how to thank you!! Where can i elaborate on this. ?
Estarta
-
It worked, i dont know how to thank you!! Where can i elaborate on this. ?
Estarta
Well you can think about passing back a FAILED or SUCCEEDED values back, wrap it up in a transaction, there are thousands of possibilities, but you'll find out about them more as you progress.
Kind Regards, Gary
My Website || My Blog || My Articles