ASP.NET Tutorial 4- How to Create a Login website - Connecting Database to Registration Page

Поділитися
Вставка
  • Опубліковано 6 лют 2025
  • ASP.NET Database Connection.ASP.NET Web Forms Database
    How to connect asp.net to a database.
    ★★★Top Online Courses From ProgrammingKnowledge ★★★
    Python Programming Course ➡️ bit.ly/2vsuMaS ⚫️ bit.ly/2GOaeQB
    Java Programming Course ➡️ bit.ly/2GEfQMf ⚫️ bit.ly/2Vvjy4a
    Bash Shell Scripting Course ➡️ bit.ly/2DBVF0C ⚫️ bit.ly/2UM06vF
    Linux Command Line Tutorials ➡️ bit.ly/2IXuil0 ⚫️ bit.ly/2IXukt8
    C Programming Course ➡️ bit.ly/2GQCiD1 ⚫️ bit.ly/2ZGN6ej
    C++ Programming Course ➡️ bit.ly/2V4oEVJ ⚫️ bit.ly/2XMvqMs
    PHP Programming Course ➡️ bit.ly/2XP71WH ⚫️ bit.ly/2vs3od6
    Android Development Course ➡️ bit.ly/2UHih5H ⚫️ bit.ly/2IMhVci
    C# Programming Course ➡️ bit.ly/2Vr7HEl ⚫️ bit.ly/2W6RXTU
    JavaFx Programming Course ➡️ bit.ly/2XMvZWA ⚫️ bit.ly/2V2CoAi
    NodeJs Programming Course ➡️ bit.ly/2GPg7gA ⚫️ bit.ly/2GQYTQ2
    Jenkins Course For Developers and DevOps ➡️ bit.ly/2Wd4l4W ⚫️ bit.ly/2J1B1ug
    Scala Programming Tutorial Course ➡️ bit.ly/2PysyA4 ⚫️ bit.ly/2PCaVj2
    Bootstrap Responsive Web Design Tutorial ➡️ bit.ly/2DFQ2yC ⚫️ bit.ly/2VoJWwH
    MongoDB Tutorial Course ➡️ bit.ly/2LaCJfP ⚫️ bit.ly/2WaI7Ap
    QT C++ GUI Tutorial For Beginners ➡️ bit.ly/2vwqHSZ
    ★★★ Online Courses to learn ★★★
    Get 2 FREE Months of Unlimited Classes from skillshare - skillshare.eqc...
    Data Science - bit.ly/2lD9h5L | bit.ly/2lI8wIl
    Machine Learning - bit.ly/2WGGQpb | bit.ly/2GghLXX
    Artificial Intelligence - bit.ly/2lYqaYx | bit.ly/2NmaPya
    MERN Stack E-Degree Program - bit.ly/2kx2NFe | bit.ly/2lWj4no
    DevOps E-degree - bit.ly/2k1PwUQ | bit.ly/2k8Ypfy
    Data Analytics with R - bit.ly/2lBKqz8 | bit.ly/2lAjos3
    AWS Certification Training - bit.ly/2kmLtTu | bit.ly/2lAkQL1
    Projects in Java - bit.ly/2kzn25d | bit.ly/2lBMffs
    Machine Learning With TensorFlow - bit.ly/2m1z3AF | bit.ly/2lBMhnA
    Angular 8 - Complete Essential Guide - bit.ly/2lYvYRP
    Kotlin Android Development Masterclass - bit.ly/2GcblsI
    Learn iOS Programming Building Advance Projects - bit.ly/2kyX7ue
    ★★★ Follow ★★★
    My Website - www.codebind.com
    DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!
    Creating sql database connection in asp.net web application
    How to make database connectivity in asp.net
    Make connection to database in ASP.NET
    c# - asp.net database connection
    connect jqgrid to database
    using WebSecurity.InitializeDatabaseConnection() to
    CREATE DATABASE permission denied in database
    How to connect asp.net to a database
    Create a separated class for database connection

КОМЕНТАРІ • 367

  • @drewkennedy805
    @drewkennedy805 11 років тому

    Tip: Don't place your conn.Close() inside the try block. If an exception is thrown before it reaches that line, the connection won't close. Best practice is to always place it in a "finally" block, and make your SqlConnection variable global.
    Excellent tutorial as usual.

  • @ememeable
    @ememeable 3 роки тому +1

    I thankyou very much and pray God bless all your endeavors

  • @lawrencemmethi598
    @lawrencemmethi598 7 років тому +1

    Great video and I'm beginner for ASP.NET Web Programming.

  • @xcysio75
    @xcysio75 8 років тому +2

    Good turtorial but .. for beginners. It is important to learn also good programming habits ex: sql injection - you need to use sql parameters, in sql tables we can use (and its much easier) autoincrement identity fields for unique ID's - the database will do it for you.

  • @theRealRKI
    @theRealRKI 7 років тому

    I don't know why but your tutorials are better than any American or German. You go through the matter of creating everything in one video where other people use pre-made forms.

  • @bhawanmalhi3532
    @bhawanmalhi3532 5 років тому

    hey i am watching your videos from tutorial 1 and to be honest they are very helpful.Thanks so much..

  • @sergezeda9738
    @sergezeda9738 9 років тому

    Great tutorial session. Thanks to all of you for your invaluable contribution to this online forum.

  • @nirbhaysingh8393
    @nirbhaysingh8393 5 років тому

    bro i love you... u jst solved my prblm in minutes.... @@@salute.

  • @doomhammer544
    @doomhammer544 6 років тому

    Thank you very much for this tutorial. It was a great help. Thank you for explaining things slowly and methodically. Also to solve the problem with the table name problem I did the following: [dbo].[Table] it worked for me.

  • @codegen8947
    @codegen8947 9 років тому

    hey bro ..you can type 'if' and hit 'tab' once or twice and it will get you that 'if' snippet much quicker. This also works for other things like for loops, while loops, etc :)

  • @marusapahor5792
    @marusapahor5792 6 років тому

    This works. Also use parameterized queries to avoid SQL injections.
    SqlCommand checkuser = new SqlCommand("SELECT COUNT(*) FROM [UserData] WHERE ([UserName] = @UserName)", conn);
    checkuser.Parameters.AddWithValue("@UserName", TextBoxUN.Text);
    int temp = (int)checkuser.ExecuteScalar();
    if (temp > 0)
    {
    Response.Write("User already exists!");
    }
    conn.Close();

  • @michaeljames5485
    @michaeljames5485 10 років тому +5

    Remember to make ID null and not a primary key inside Userdata, otherwise you will get an error since you would be leaving the primary key Null since we're not adding a value yet

  • @didomike
    @didomike 4 роки тому +2

    Good it's work, but the ID field in the table Userdata must be declared as PRIMARY KEY IDENTITY go to Column properties below of it scroll down and find Identity Specification, expand it and you will find Is Identity make it Yes. Now choose Identity Increment right below of it give the value you want to increment in it.

  • @uwrl
    @uwrl 8 років тому +1

    Fantastic tutorial. I have learned so much! Thank you!!

  • @aghani3albal
    @aghani3albal 4 роки тому

    Thanks for your clear and detailed explanation!

  • @fnas4809
    @fnas4809 8 років тому

    ALTHOGH IT IS SO SLOW BUT IT IS SOOO HELPFUL. THANK YOU SO MUCH SIR

  • @BimalDaslol
    @BimalDaslol 10 років тому +2

    very very thankful to you to provide such a video...... thanks for your excellent effort.
    I Want To know Is it mendetory to learn html for building webpages using asp.net ?

  • @ammurjs6852
    @ammurjs6852 8 років тому

    I Got the Coding and its working... I checked ..
    Paste the below coding in your program
    Write the code in page load.. If you want else function u can use...
    otherwise u can leave it.
    u can use if statement only.
    if anyone have doubt can ask
    Page_Load
    {
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UserDBConnectionString"].ConnectionString);
    using (SqlCommand cmd = new SqlCommand("select * from tblUserdata where UserName = @uname", con))
    {
    con.Open();
    cmd.Parameters.AddWithValue("@uname", TextBoxUN.Text);
    SqlDataReader dr = cmd.ExecuteReader();
    if (dr.HasRows)
    {
    Response.Write("userid already exists");
    Response.Redirect("UserDBDetails.aspx");
    }
    else
    {
    Response.Write("userid doesn't exists");
    //Create new user
    }
    }
    }

  • @martincday007
    @martincday007 8 років тому +7

    This is an excellent series and much appreciated, although considering some of the ungrateful comments you get I wonder why you bother.
    Is there any particular reason/benefit why the check for the unique username is performed in the form's Load section as opposed to the button.click? It just seems that to me that it would seem more logical to have it all in the button.click subroutine.

    • @hamza4283
      @hamza4283 7 років тому

      getting error on this line somebody plz help
      line23: int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
      my code is this--
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Data.SqlClient;
      using System.Configuration;
      namespace LoginPage
      {
      public partial class Registration : System.Web.UI.Page
      {
      int temp = 0;
      protected void Page_Load(object sender, EventArgs e)
      {
      if (IsPostBack)
      {
      SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
      conn.Open();
      string checkUserdata = " select count(*) from [UserData] where='" + TextBoxUN.Text + "'";
      SqlCommand com = new SqlCommand(checkUserdata, conn);
      int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
      if (temp == 1) {
      Response.Write("User already exist");
      }
      conn.Close();
      }
      }
      protected void TextBox5_TextChanged(object sender, EventArgs e)
      {
      }
      protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
      {
      }
      protected void TextBox4_TextChanged(object sender, EventArgs e)
      {
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
      try
      {
      SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
      conn.Open();
      string insertQuery = "insert into UserData(UserName,Email,Password,Country) values (@Uname,@email,@password,@country) ";
      SqlCommand com = new SqlCommand(insertQuery, conn);
      int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
      conn.Close();
      com.Parameters.AddWithValue("@Uname", TextBoxUN.Text);
      com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
      com.Parameters.AddWithValue("@password", TextBoxPass.Text);
      com.Parameters.AddWithValue("@country", DropDownCountry.SelectedItem.ToString());
      com.ExecuteNonQuery();
      Response.Redirect("Manager.aspx");
      Response.Write("Registration completed");
      }
      catch (Exception ex)
      {
      Response.Write("Error" + ex.ToString());
      }
      }
      }
      }

  • @hamzakarabag6786
    @hamzakarabag6786 8 років тому +19

    in order to solve the problem about Convert.ToInt32(com.ExecuteScalar().ToString());
    you need to change the upper line as;
    string checkuser = "select count(*) from [UserData] where UserName = ' "TextBoxUN.Text"'";
    simply put square brackets to each side of the tables name

  • @umeshsaini007
    @umeshsaini007 6 років тому

    you have really made it easy for me
    thanks man

  • @zaghumkabir9161
    @zaghumkabir9161 5 років тому

    It Helped alot!!!jazakiAllaah

  • @shruthisooriya986
    @shruthisooriya986 10 років тому

    Its good...it would be more easier if you had attached the code in text form so that we can only copy paste :)

  • @shammaal-kaabi9524
    @shammaal-kaabi9524 10 років тому +4

    With the code you have demonstrated, adding a new user with a username that already exists in the database does not show the error message you posted, it adds the users to the database regardless of already being in the database.

    • @vimming6459
      @vimming6459 10 років тому

      True,
      I even added debug code to that if (IsPostBack) statement. So my guess is that none of it gets called.

    • @shammaal-kaabi9524
      @shammaal-kaabi9524 10 років тому

      Exactly, this basically means that once the page is loaded then the code written will be executed, but my guess is it's not executed because the user is directed to another page.

    • @vimming6459
      @vimming6459 10 років тому

      박송미
      This is correct. I took out the redirection code that was fired when you press the regsiter button and now it gets called. It's a bit pointless having a button that just submits user data and refreshes the page but I suppose it'll have to do for now.
      By the way it's probably a better idea to check that 'temp' is not 0, rather than is 1.
      So it looks like
      if (temp !=0){
      Response.Write("user already exists);
      }

    • @vimming6459
      @vimming6459 10 років тому +1

      I've managed to get mine working. I've put the code onto pastebin, feel free to look at it. It's in VB.NET but it shouldn't be too hard to port it over to C#
      pastebin.com/YSDH9Q5w
      It's pretty messy at the moment but I'll get round to refactoring eventually

    • @shammaal-kaabi9524
      @shammaal-kaabi9524 10 років тому

      Thanks! I'll definitely check it out !

  • @SushikillerHD
    @SushikillerHD 7 років тому

    I like how he says "Okey?" sometimes :) I'm here saying YUS! to my screen everytime he says that ;)

  • @maazsheikh6696
    @maazsheikh6696 10 років тому +2

    nice tutorial very helpfull

  • @ghulamemustafa3715
    @ghulamemustafa3715 7 років тому

    hello
    Good serial to learn ASP.net v good explaniation
    But backround sounds are distarbing pls minimise tha backround sounds in further vedios

  • @nicetime6975
    @nicetime6975 9 років тому +3

    hi, there is a bug.. whenever u click on button and having same Username "temp will increment by 1" so add carl several time and u will see that one time it goes through "user already exist" and all will be inserted to database so on button_click we should have restriction when temp==1 to avoid inserting the values. If am wrong plz inform me .

  • @ManojYadwad2
    @ManojYadwad2 9 років тому +1

    99% successful in one attempt. only check user is not working in "ASP.NET Tutorial 4". It accepts same usernames without any error. and you have not performed cross check in the video where a same username is entered it should give a error message. Thank you for your great tutorials. please reply

    • @Jakubeslaw
      @Jakubeslaw 8 років тому

      +Manoj Yadwad Same problem

    • @md.tanvirrahman5908
      @md.tanvirrahman5908 8 років тому

      try this:
      public partial class Registration : System.Web.UI.Page
      {
      Int32 temp = 0;
      protected void Page_Load(object sender, EventArgs e)
      {
      if (IsPostBack)
      {
      SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
      conn.Open();
      string checkuser = "select count(*) from [userdata] where Username='" + username.Text + "'";
      SqlCommand com = new SqlCommand(checkuser, conn);
      int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
      if (temp > 0)
      {
      MessageBox.Show("already exist");
      Response.Redirect("Registration.aspx");
      }
      conn.Close();
      }
      }
      protected void Button3_Click(object sender, EventArgs e)
      {
      try
      {
      SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
      conn.Open();
      string insertquery = "insert into [userdata] (Username,Email,Password,Country) values(@uname,@email,@password,@country) ";
      SqlCommand com = new SqlCommand(insertquery, conn);
      com.Parameters.AddWithValue("@uname", username.Text);
      com.Parameters.AddWithValue("@email", email.Text);
      com.Parameters.AddWithValue("@password", password.Text);
      com.Parameters.AddWithValue("@country", droplist.SelectedItem.ToString());
      com.ExecuteNonQuery();
      MessageBox.Show("Successfully submitted");
      Response.Redirect("Manager.aspx");
      conn.Close();
      }
      catch (Exception E)
      {
      Response.Write("Error" + E.ToString());
      }
      }
      }

    • @mayurnagare8251
      @mayurnagare8251 8 років тому

      thts not work

  • @harivayugurupreranee
    @harivayugurupreranee 10 років тому

    Thanks a lot
    i got perfect out put

  • @sayeedinamdar7214
    @sayeedinamdar7214 5 років тому

    Thank You Very Much Sir.

  • @AyushAnandayush
    @AyushAnandayush 6 років тому

    for null object reference
    go to web config and add:-

    for appropriate connectionString="Data Source=....."
    go to your Registration database right click
    select proprieties
    copy connection string from their.
    Hope this helps.

  • @Ashronaldo07
    @Ashronaldo07 11 років тому

    great worked so far (y)

  • @Nick-me9sf
    @Nick-me9sf 9 років тому +1

    hello, your tutorials are awesome. I receive this error "Object refference not set to an instance of an object" on the line where I create the new sqlconnection. can you help me, please?!

  • @darhtmedia2988
    @darhtmedia2988 6 років тому

    Video is good but i wish you would explain what all the lines of code mean.

  • @SureshPalarimath
    @SureshPalarimath 7 років тому

    Hi,
    Why you are writing code in Pageload() and where you are using it or where it is utilized?

  • @niranjankumar9958
    @niranjankumar9958 2 роки тому

    thank u sir
    please provide us syllabus of asp.net

  • @deepeshpawar5953
    @deepeshpawar5953 10 років тому +8

    Your video was good but you didnt provide the solution for username exists..
    If you are pasting such a good video you should provide relevant solutions for the subscribers..@ProgrammingKnowledge

    • @ImranShaikh-vj4kc
      @ImranShaikh-vj4kc 7 років тому

      Same reply functionality is not working sir

    • @code_aalim
      @code_aalim 7 років тому +1

      Error solved
      Just remove the double qoutes from checkUser like
      before
      SqlCommand com = new SqlCommand("checkUser", conn);
      then after
      SqlCommand com = new SqlCommand(checkUser, conn);
      welcome
      Subscribe my channel please

    • @Boing2720
      @Boing2720 5 років тому

      @@code_aalim In the video there are no double quotes, and duplicates still happen, please help @ProgrammingKnowledge

  • @javascriptguy2417
    @javascriptguy2417 7 років тому

    good channel

  • @chaimaabelbergui9673
    @chaimaabelbergui9673 7 років тому +2

    "when i click submit, it just reloads the same registration form with passwords empty, and doesn't save data to the Database. Doesn't redirect to manager.aspx, and no success message either. And no error either". I have the same problem, any suggestion?

  • @vaibhavhumane5197
    @vaibhavhumane5197 9 років тому +8

    int temp = Convert.ToInt32(con.ExecuteScalar().ToString()); it gives error at these line at the semicolen stuff

  • @fatoumatabocoum1763
    @fatoumatabocoum1763 9 років тому

    God bless you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @1452364789
    @1452364789 8 років тому

    great videos, subscribed :)

  • @zareenasikander4238
    @zareenasikander4238 9 років тому

    Best tutorial

  • @KaliGold
    @KaliGold 10 років тому +1

    You didnt test to see what happens when you enter a user name that is already there. The way you have it, it still adds the user even if the username is already there.
    Ok, so I used a static boolean variable in a new class file I added. If there is a dup user then i set it to true and check the value in button_click. If its true i just use the "return" word to bypass submit button click code.

    • @code_aalim
      @code_aalim 7 років тому

      Error solved
      Just remove the double qoutes from checkUser like
      before
      SqlCommand com = new SqlCommand("checkUser", conn);
      then after
      SqlCommand com = new SqlCommand(checkUser, conn);
      welcome
      Subscribe my channel, please

  • @mohammedzahid7992
    @mohammedzahid7992 10 років тому +10

    Slightly modify the code to show "User already Exists"
    public partial class LoginPage : System.Web.UI.Page
    {
    int temp=0;
    protected void Page_Load(object sender, EventArgs e)
    {
    if (IsPostBack)
    {
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
    conn.Open();
    string checkuser = "select count(*) from registration where username='" + TBusername.Text + "'";
    SqlCommand com = new SqlCommand(checkuser, conn);
    temp = Convert.ToInt32(com.ExecuteScalar().ToString());
    if (temp==1)
    {
    Response.Write("User already exists");

    }
    conn.Close();
    }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    if (temp == 0)
    {
    try
    {
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
    conn.Open();
    string insertquery = "insert into registration (username,emailid,password,country) values (@uname,@email,@password,@country)";
    SqlCommand com = new SqlCommand(insertquery, conn);
    com.Parameters.AddWithValue("@uname", TBusername.Text);
    com.Parameters.AddWithValue("@email", TBemail.Text);
    com.Parameters.AddWithValue("@password", TBpass.Text);
    com.Parameters.AddWithValue("@country", DDcountry.SelectedItem.ToString());
    com.ExecuteNonQuery();
    Response.Redirect("Managers.aspx");
    Response.Write("Registration Successful");
    conn.Close();
    }
    catch (Exception ex)
    {
    Response.Write("error :" + ex.ToString());
    }
    }
    }
    }

    • @sortmoney6438
      @sortmoney6438 10 років тому +1

      Thanks. You might want to change "if (temp == 1)" with "if (temp != 0)". This will also show the message.

    • @deepeshpawar5953
      @deepeshpawar5953 10 років тому

      ***** Can you provide me how you fix this issue

    • @rodneyperello
      @rodneyperello 9 років тому

      Mohammed Zahid
      Good thing I looked at your comment. You pointed me to the right direction! Thanks!

    • @TheDoxenixx
      @TheDoxenixx 9 років тому +3

      Mohammed Zahid it didn't helped

    • @priyavijay5376
      @priyavijay5376 7 років тому

      am getting this error NullReferenceException: Object reference not set to an instance of an object

  • @Shirancnet
    @Shirancnet 10 років тому

    Thank you very much..
    .

  • @travelwithnaeemhasan
    @travelwithnaeemhasan 7 років тому

    Thank a lot sir appreciated

  • @aaryankumarandarpa9774
    @aaryankumarandarpa9774 8 років тому

    ser ye sab vedios hindi me banaye taki jinko english nhi vi bhi ye sab sikh sake pls.......

  • @AvinashKumar-nl2cg
    @AvinashKumar-nl2cg 10 років тому +3

    An expression of non-boolean type specified in a context where a condition is expected, near 'raja ba'.
    sir igot a Exception on line 19
    int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
    pls help me

  • @jonelbacalla8047
    @jonelbacalla8047 7 років тому +1

    Use "select *" instead of "select count(*)"
    Replace temp statement with:
    SqlDataReader reader = com.ExecuteReader();
    if (reader.HasRows)
    {
    //User already exists
    }
    else
    {
    //Doesn't exist
    }

    • @prasadchavan42000
      @prasadchavan42000 5 років тому

      dude you are the best
      thank you so much ..........

  • @balabrahmam8844
    @balabrahmam8844 9 років тому +1

    After executing it, I can enter values in Username,... fields but after submitting it is showing an error: "An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code". Can you please suggest me to correct it. Thank you.

  • @tedchirvasiu
    @tedchirvasiu 10 років тому

    Thanks a ton!

  • @boloxbb
    @boloxbb 7 років тому

    int temp = Convert.ToInt32(con.ExecuteScalar().ToString());
    I had that problem. I just made everything from the very begining and it works now. I think that a name of table cannot be "Table". Try that

  • @darkangel5885
    @darkangel5885 9 років тому

    Your tutorials are very useful! As a beginner, I find these steps very easy to follow. :)
    I just have a question. I tried using the same username but it didn't display the message "User already exists". Could you please check this code that I'm using? Thanks in advance!
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Configuration;
    public partial class Registration : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if(IsPostBack)
    {
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
    conn.Open();
    string checkuser = "select count(*) from UserData where UserName='" + TextBoxUsername.Text + "'";
    SqlCommand com = new SqlCommand(checkuser, conn);
    int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
    if (temp == 1)
    {
    Response.Write("User already exists");
    }
    conn.Close();
    }
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
    try
    {
    Guid newGUID = Guid.NewGuid();
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
    conn.Open();
    string insertQuery = "insert into UserData (ID,UserName,Email,Password,Country) values (@ID ,@Uname ,@email ,@password ,@country)";
    SqlCommand com = new SqlCommand(insertQuery, conn);
    com.Parameters.AddWithValue("@ID", newGUID.ToString());
    com.Parameters.AddWithValue("@Uname", TextBoxUsername.Text);
    com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
    com.Parameters.AddWithValue("@password", TextBoxPw.Text);
    com.Parameters.AddWithValue("@country", DropDownListCountry.SelectedItem.ToString());
    com.ExecuteNonQuery();
    Response.Redirect("Manager.aspx");
    Response.Write("Registration is successful");
    conn.Close();
    }
    catch(Exception ex)
    {
    Response.Write("Error:"+ex.ToString());
    }
    }
    }

  • @nargisehsan5358
    @nargisehsan5358 9 років тому +6

    how to fix in this line:
    int temp = Convert.ToInt32(con.ExecuteScalar().ToString());
    Description: Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: ExecuteScalar: Connection property has not been initialized.
    - via YouPak(.com)

    • @shubhamjain-nx2sb
      @shubhamjain-nx2sb 9 років тому +2

      +nargis ehsan add [] to your table name e.g. [Table]

    • @Mohitkandalgaonkar4444
      @Mohitkandalgaonkar4444 8 років тому

      +shubham jain i had the same error but for some reason it did't fix it i type the table name in the square bracket

    • @AMANKUMAR-qd8mt
      @AMANKUMAR-qd8mt 8 років тому

      hey nargis i m having d same error hw shld i crrct it.?????/

    • @hamza4283
      @hamza4283 7 років тому

      getting error on this line somebody plz help
      line23: int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
      my code is this--
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Data.SqlClient;
      using System.Configuration;
      namespace LoginPage
      {
      public partial class Registration : System.Web.UI.Page
      {
      int temp = 0;
      protected void Page_Load(object sender, EventArgs e)
      {
      if (IsPostBack)
      {
      SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
      conn.Open();
      string checkUserdata = " select count(*) from [UserData] where='" + TextBoxUN.Text + "'";
      SqlCommand com = new SqlCommand(checkUserdata, conn);
      int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
      if (temp == 1) {
      Response.Write("User already exist");
      }
      conn.Close();
      }
      }
      protected void TextBox5_TextChanged(object sender, EventArgs e)
      {
      }
      protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
      {
      }
      protected void TextBox4_TextChanged(object sender, EventArgs e)
      {
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
      try
      {
      SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
      conn.Open();
      string insertQuery = "insert into UserData(UserName,Email,Password,Country) values (@Uname,@email,@password,@country) ";
      SqlCommand com = new SqlCommand(insertQuery, conn);
      int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
      conn.Close();
      com.Parameters.AddWithValue("@Uname", TextBoxUN.Text);
      com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
      com.Parameters.AddWithValue("@password", TextBoxPass.Text);
      com.Parameters.AddWithValue("@country", DropDownCountry.SelectedItem.ToString());
      com.ExecuteNonQuery();
      Response.Redirect("Manager.aspx");
      Response.Write("Registration completed");
      }
      catch (Exception ex)
      {
      Response.Write("Error" + ex.ToString());
      }
      }
      }
      }

    • @vikasjha6541
      @vikasjha6541 7 років тому

      hey can u just tell what error are u seeing on that line

  • @shiprakhanna9056
    @shiprakhanna9056 7 років тому

    I have tried this piece of code it is working there's no error but there is one bug that it is also accepting duplicate entries of username.... kindly revert with the solution...

  • @asmamubarak1894
    @asmamubarak1894 10 років тому +3

    I have the newest version of ASP.net and I don't have the "page_load" thing ..
    but I have .. TextBox4_TextChanged & Button1_Click
    where can I put the code you wrote instead of the "page_load"?!!

    • @puto_tv6134
      @puto_tv6134 8 років тому

      how did you solve it? I have the exact same problem

  • @khizarzafar4154
    @khizarzafar4154 7 років тому

    what does this error means ?
    "Invalid postback or callback argument. Event validation is enabled using in configuration or in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation."

  • @falgundalal6741
    @falgundalal6741 9 років тому +1

    you missed to clarify the ID how to replace in database

  • @iamtauqeerahmad
    @iamtauqeerahmad 7 років тому

    Sir you're great but change this line 20 to this
    string checkuser= "select count(*)from [UserData] where UserName= '"+TextBoxUN.Text +"'";
    other code is okay

  • @koilk
    @koilk 10 років тому

    if anybody out there is getting:
    No mapping exists from object type System.Web.UI.WebControls.ListItem
    add the toString() to the end of your drop down list item:
    com.Parameters.AddWithValue("@country",
    DropDownListCountry.SelectedItem.ToString());

  • @kalyanpavan8028
    @kalyanpavan8028 9 років тому

    hi bro i am using vs 2015 when i double click on submit button it is going to the .aspx file but in video it is going to the .aspx.cs file plz help me how can i do that.how can i write sql connection commands plz help me

  • @megajar100
    @megajar100 6 років тому

    it works!

  • @rizwanafathima4684
    @rizwanafathima4684 8 років тому

    I did everything as shown in the video and im getting 2 errors one in sqldatasource box tat it doesn't contain select query and another one is on Conn.Open();...pls help me to fix thus problem

  • @roastwithpk1866
    @roastwithpk1866 7 років тому

    its not showing username already exist...instead its going on taking the same username n saving it in database

  • @SilentAssassin118
    @SilentAssassin118 10 років тому

    is it necessary to create a Manager.aspx for the connection string?

    • @shammaal-kaabi9524
      @shammaal-kaabi9524 10 років тому

      he said it was for demonstration purposes only like to be able to see the newly added user in the database

  • @asmamubarak1894
    @asmamubarak1894 10 років тому +1

    and One more thing , you have so many using system and I don't have any

  • @gustavojr10
    @gustavojr10 10 років тому

    When I click twice at the button "Submit" it redirects me to a created at the .aspx file instead of redirecting me to the .cs file. When I create, by myself, the .cs file I get some errors calling the TextBoxs.
    How can I solve it?
    I can work at the (at .aspx file) but how do I call the c# libraries like:
    "using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Configuration;"
    Thank you.

  • @victordyusha3977
    @victordyusha3977 8 років тому

    How do you make numbers in Id column to increment every time you register someone new?

    • @lifet4800
      @lifet4800 8 років тому

      +Victor Dyusha use identity ........ such as (id int identity primary key)

  • @albertzabergja723
    @albertzabergja723 8 років тому +3

    You just... you just... YES we just, but can you explain why are you writing the code ?
    For Example, why do you need " if (isPostBack) " and so on !?

    • @miguelitossss199
      @miguelitossss199 4 роки тому

      It is for checking if the page goes from a fresh load or from a post action, it returns a boolean

  • @manishnair4723
    @manishnair4723 8 років тому

    sir i really need help because this all code is written in c# and I need visual basic

  • @anastacio94
    @anastacio94 10 років тому +5

    Please help me with this error
    "Type 'System.Web.UI.WebControls.SqlDataSource' does not have a public property named 'SelectQuery ".
    What can i do?

    • @ceweke20
      @ceweke20 10 років тому +1

      same issue! ... still have it?

    • @donxnik
      @donxnik 10 років тому

      Same Here. . .

    • @ktlnaysbl5624
      @ktlnaysbl5624 8 років тому

      IT SHOULD BE LIKE THIS

    • @thanemane
      @thanemane 7 років тому

      after doing the change the problem is not solved. ;( ;( please help

    • @ersonmacatangay983
      @ersonmacatangay983 4 роки тому

      @@thanemane I solve this problem using what Carl Patrick Guerrero use in the SqlDataSource
      then add in your

  • @developerHelper
    @developerHelper 5 років тому

    he i am bsc it student i want to ask you some questions about my project can you help me?

  • @aloop01
    @aloop01 10 років тому

    ProgrammingKnowledge
    Great tutorial Sir. But whenever I try to run the program. It gives me this error:
    "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
    It' having some problem with Opening the connection. Any solutions to this problem?

  • @kmuralikrishna1582
    @kmuralikrishna1582 5 років тому

    User already exist is not working, even entering same user name multiple times its saving in to database table, any corrections here ?

  • @brainbytes1202
    @brainbytes1202 7 років тому

    Just so you know change the if statement from if(temp == 1) to if(temp >= 1), just in case somebody is testing

  • @barakkadosh
    @barakkadosh 9 років тому

    very good code but when i click on the submit jast reload and the data not in the database how can i fix it ? please help

  • @samsonmark2212
    @samsonmark2212 8 років тому

    Error 2 'ASP.default_aspx' does not contain a definition for 'TextBox1_TextChange' and no extension method 'TextBox1_TextChange' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) C:\Users\user\Documents\Visual Studio 2010\WebSites\WebSite1\Default.aspx 104
    i got this error how to fix it?

  • @aniketbhave1719
    @aniketbhave1719 5 років тому

    Can you create canteen project please

  • @vandanasharma9001
    @vandanasharma9001 8 років тому +1

    int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
    this line is giving me error
    An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code.
    please help!!

  • @gyanendrashahg
    @gyanendrashahg 6 років тому

    But I needs update and delete data in data connection string or database table

  • @bryantma2116
    @bryantma2116 8 років тому

    I insert an existing user name but the registration is also successful. The statement "User already exists" doesn't appear. Why?

  • @UmVtCg
    @UmVtCg 9 років тому +1

    Can you show the whole code at the end? there is no way to verify if the correct code is entered.

    • @regrich6030
      @regrich6030 9 років тому +4

      I finally got it functional. Here my code:
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Data.SqlClient;
      using System.Configuration;
      public partial class Registration : System.Web.UI.Page
      {
      protected void Page_Load(object sender, EventArgs e)
      {
      if (IsPostBack)
      {
      SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
      conn.Open();
      string checkuser = "select count(*) from [UserData] where Username='"+ TextBoxUN.Text + "'";
      SqlCommand com = new SqlCommand(checkuser, conn);
      int temp = Convert.ToInt32(com.ExecuteScalar().ToString ());
      if (temp == 1)
      {
      Response .Write ("User already Exists");
      }
      conn .Close();
      }
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
      try
      {
      SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
      conn.Open();
      string insertQuery = "INSERT INTO [UserData] ([UserName],[Email],[Password],[Country]) VALUES (@Uname ,@email ,@password ,@country)";
      SqlCommand com = new SqlCommand(insertQuery, conn);
      com.Parameters.AddWithValue("@Uname", TextBoxUN.Text);
      com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
      com.Parameters.AddWithValue("@password", TextBoxPass.Text);
      com.Parameters.AddWithValue("@country", DropDownListCountry.SelectedItem .ToString ());
      com.ExecuteNonQuery();
      Response.Write("Account has been successfully created");
      Response.Redirect("Manager.aspx");
      conn.Close();
      }
      catch (Exception ex)
      {
      Response.Write("Error:" +ex.ToString());
      }
      }
      }

    • @23kamalg
      @23kamalg 8 років тому

      thanks this works!

  • @tanhoyzer
    @tanhoyzer 11 років тому +3

    I have exception here int temp = Convert.ToInt32(com.ExecuteScalar().ToString()); when I press submit button please send me full code.

    • @MLforSecurity
      @MLforSecurity 10 років тому

      I had already same problem.but it solved! you should change your Table name that you saved in database .change the name Table to Table1 or something else

  • @MrDilip1435
    @MrDilip1435 10 років тому

    Thanku Sir

  • @tanvibobhate4128
    @tanvibobhate4128 3 роки тому

    I know it is late ...But i have a doubt and i really need to run the code...I have done all the forms and databse there is no issue in it bt When I run it takes me to Registration Page .cs code showing mess that object not set to an instance of an object..I f any body know Plzz help me with it ...

  • @rhunaligosavi8423
    @rhunaligosavi8423 9 років тому

    my error generate inccorrect syntax near 'UserData'
    this is my select string = select count(*) from Table where UserData = '" + txtUN.Text + "'";
    whats the error?
    error:
    Line 19: SqlCommand com = new SqlCommand(checkuser, con);
    Line 20:
    Line 21: int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
    Line 22: if (temp == 1)
    Line 23: {

  • @mohammadtalaie2773
    @mohammadtalaie2773 9 років тому

    I have done all the things you said but when i click on the submit button nothing happens just the page reloads!
    What am i supposed to do???!!!
    please help!!!

  • @ritheshreddy9785
    @ritheshreddy9785 11 років тому

    thanq .

  • @guillermovargas3135
    @guillermovargas3135 10 років тому +1

    The username validation is not working. No one is providing complete answers.

  • @10000years
    @10000years 9 років тому +1

    my error generate inccorrect syntax near 'UserData'
    this is my select string = select count(*) from Table where UserData = '" + txtUN.Text + "'";
    whats the error?

    • @b8addict
      @b8addict 9 років тому +2

      +jenan savanath You need to encapsulate your Table with []. Example: select count(*) from [Table]

    • @10000years
      @10000years 9 років тому +1

      +eliteowner121 oh yeah i forgot about that...thanks. I totally forgot about 'Table' being a reserved keyword.

  • @nishasagar456
    @nishasagar456 5 років тому

    conn.parameters.addwithvalue is code line m parameter par error show kar raha hai plz tell me how can i remove it

  • @rameshmarthula8051
    @rameshmarthula8051 8 років тому

    errorSystem.NullReferenceException: Object reference not set to an instance of an object. at registration.WebForm1.Button1_Click(Object sender, EventArgs e) in c:
    egistration
    egistration\WebForm1.aspx.cs:line 38

  • @noshairfarooq4032
    @noshairfarooq4032 9 років тому +2

    The page is still adding the same user name registration i just typed the same code as you did...

    • @Vaish1304
      @Vaish1304 9 років тому

      +Noshair Farooq Yes same here.I guess this is not the code

    • @noshairfarooq4032
      @noshairfarooq4032 9 років тому

      well do share if you get it right

    • @89Ssik
      @89Ssik 9 років тому

      +Noshair Farooq Yeah, I was thinking the same, he didn't even try to write same name in this demo, if he did, I'm sure he would get same outcome as we do.. I hope someone can help us with this, as it's quite important to not allow the users to choose same username, but to get some sort of validation, where it wouldn't allow same UserName to be used twice. I'll probably just google it tbh :D

    • @darkangel5885
      @darkangel5885 9 років тому

      +Noshair Farooq oh i thought I was the only one experiencing this and I was also hoping that he would try to input the same username. :(

  • @derzasekolahdidd
    @derzasekolahdidd 10 років тому

    why did you put the userCheck in page_load event?

  • @maeanneespiritu
    @maeanneespiritu 8 років тому

    I encounter an error
    Must declare the scalar variable "@FName". at System.Data.SqlClient.SqlConnection.

  • @shashisingh9803
    @shashisingh9803 6 років тому

    S Showing error the name 'TextUn' does not exist in the current context regis

  • @Arhaanmastar
    @Arhaanmastar 10 років тому

    I have also Noticed that , ID does Not Auto Increment during Registration .
    Set that too !!!

  • @fazlurrahman931
    @fazlurrahman931 4 роки тому

    Although i followed same codes, still another user could be created with the same user name. Why is it?