Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Register a new user

Register a new user

Scheduled Pinned Locked Moved ASP.NET
questiondatabase
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MoeInsairat
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • M MoeInsairat

      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

      G Offline
      G Offline
      GaryWoodfine
      wrote on last edited by
      #2

      use a sql query to check if the name exists in the DB

      Kind Regards, Gary


      My Website || My Blog || My Articles

      M 1 Reply Last reply
      0
      • G GaryWoodfine

        use a sql query to check if the name exists in the DB

        Kind Regards, Gary


        My Website || My Blog || My Articles

        M Offline
        M Offline
        MoeInsairat
        wrote on last edited by
        #3

        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

        G 1 Reply Last reply
        0
        • M MoeInsairat

          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

          G Offline
          G Offline
          GaryWoodfine
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • G GaryWoodfine

            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

            M Offline
            M Offline
            MoeInsairat
            wrote on last edited by
            #5

            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

            G M 2 Replies Last reply
            0
            • M MoeInsairat

              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

              G Offline
              G Offline
              GaryWoodfine
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • M MoeInsairat

                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

                M Offline
                M Offline
                MoeInsairat
                wrote on last edited by
                #7

                Thanks alot :) i will try it now. Regards

                Estarta

                1 Reply Last reply
                0
                • G GaryWoodfine

                  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

                  M Offline
                  M Offline
                  MoeInsairat
                  wrote on last edited by
                  #8

                  It worked, i dont know how to thank you!! Where can i elaborate on this. ?

                  Estarta

                  G 1 Reply Last reply
                  0
                  • M MoeInsairat

                    It worked, i dont know how to thank you!! Where can i elaborate on this. ?

                    Estarta

                    G Offline
                    G Offline
                    GaryWoodfine
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups