Asp.net Registration Form with SQL Database Validation Part – 2

Asp.net Registration Form with SQL Database Validation Part – 2


In the First video we are created the Registration form Design and now we are connecting database to our form. if you database connection is lost and you cannot cannot create the file then manually add the file. You can add Database file from here. Or You can add this file from clicking on the app data folder and add SQL Server Database file. Double click on Database.mdf file to open Create Table. Right Click on table and select New query. You can Create Table Graphically You can see your table is created successfully. add SQLDataSource in the bottom of the body. Select Your Database File. You can use this connection string also to connect database. but we are using this Configation Connection String to connect database. Click on test Query to check the connection. now we are creating a onlick event on the Button to Submit data. add the globle namespace files to use sql database commands. Create new SQl Connection. we are store the sql command in the string. make sure the name is correct otherwise you will get error massage. Create new Sql Command. And pass the sql command string to new sql command. and also pass the connectionstring. add the Values parameters names. make sure the name of your values parameters is correct. add textbox name which value is want to be inserted into your table. Use ExecuteNonQuery to Execute Insert, Update and Delete Commands. and at the last close the database connection. Add label to show that you are successfully register. now we are adding validation controls for our Textbox. the first textbox validation is require field Validation. if you add this validation you cannot leave empty textbox. Regular Expression Validator is use to validate user Input. We are using this validation to make sure password is between 3 to 10 Characters. Compare Validator is use to Compare the input value with other input Control. link of part -1 is in the description. you can see the error massage. if you have any question please ask me on the video comment section. you can download this project from the description.

Daniel Ostrander

Related Posts

23 thoughts on “Asp.net Registration Form with SQL Database Validation Part – 2

  1. Santosh Sahoo says:

    HI,

    I am getting this error

    parsing "[a-zA-Z0-9'#@&.]{3-10}$" – Unterminated [] set.

    Can you please let me know? what is wrong?

  2. alex26621 says:

    Could you please check something doesn't work, nothing is added to my database:

    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 WebApplication1
    {
    public partial class Registration : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
    Response.Redirect("Login1.aspx");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PersonalConnectionString"].ConnectionString);

    try
    {
    con.Open();
    string command = "INSERT INTO Table(First_name, Surname, Email, Username, Passwords, Question, Answer) VALUES (@First_name, @Surname, @Email, @Username, @Passwords, @Question, @Answer)";
    SqlCommand cmd = new SqlCommand(command, con);

    cmd.Parameters.AddWithValue("@First_name ", firstname_b1.Text);
    cmd.Parameters.AddWithValue("@Username ", username_b1.Text);
    cmd.Parameters.AddWithValue("@Email ", email_b1.Text);
    cmd.Parameters.AddWithValue("@Username ", username_b1.Text);
    cmd.Parameters.AddWithValue("@Passwords ", password_b2.Text);
    cmd.Parameters.AddWithValue("@Question ", question_b1.Text);
    cmd.Parameters.AddWithValue("@Answer ", answer_b1.Text);
    cmd.ExecuteNonQuery();
    con.Close();
    Response.Redirect("Manager.aspx");
    }
    catch(Exception);
    {
    throw;
    }
    finally
    {

    }

    }
    }
    }

  3. simplystranger2 says:

    Very well Explained !!

  4. Sindhu Kavuri says:

    how to link this table for login that is what we have to take in initial catalog in the connection string

  5. my indian things says:

    sir i have also used radio button for gender..bt its is showing me error…
    this is my code plzz check
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;

    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    if (RadioButton1.Checked)
    {
    gender = "Male";
    }
    else if (RadioButton2.Checked)
    {
    gender = "Female";
    }
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    try
    {
    con.Open();
    string command = "INSERT INTO regi1(fname,lname,uname,email,DOB,gender,password) VALUES (@finame,@laname,@usname,@email1,@dob,@gender1,@gender2,@password1)";
    SqlCommand cmd = new SqlCommand(command, con);

    cmd.Parameters.AddWithValue("@finame", txtname.Text);
    cmd.Parameters.AddWithValue("@laname", txtlname.Text);
    cmd.Parameters.AddWithValue("@usname", txtuser.Text);
    cmd.Parameters.AddWithValue("@email1", txtemail.Text);
    cmd.Parameters.AddWithValue("@dob", TextBox1.Text);
    cmd.Parameters.AddWithValue("@gender1", RadioButton1.Text);
    cmd.Parameters.AddWithValue("@gender2", RadioButton2.Text);
    cmd.Parameters.AddWithValue("@password1", txtname.Text);

    cmd.ExecuteNonQuery();

    Label1.Visible = true;
    }
    catch (Exception)
    {
    Label1.Text = "something gose wrong..";
    throw;
    }
    finally
    {
    con.Close();
    }
    }

  6. Asha Patel says:

    Getting this error during login..

    Server Error in '/' Application.
    The system cannot find the file specified
    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.ComponentModel.Win32Exception: The system cannot find the file specified

    Source Error:

    Line 21:
    Line 22: SqlConnection con = new SqlConnection(@"Data Source=.;AttachDbFilename=|DataDirectory|student_data.mdf;Integrated Security=True;User Instance=True;");
    Line 23: con.Open();
    Line 24: SqlCommand cmd = new SqlCommand("select COUNT(*)FROM student_registration WHERE urname='" + Txturname.Text + "' and passwd='" + Txtpasswd.Text + "'");
    Line 25: cmd.Connection = con;

  7. Asha Patel says:

    Is there any video available that can teach how to create multiple page registration form?

  8. Asha Patel says:

    Sir, I am getting this error…
    Incorrect syntax near '-'.
    Incorrect syntax near '-'.
    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.Data.SqlClient.SqlException: Incorrect syntax near '-'.
    Incorrect syntax near '-'.

    Source Error:

    Line 53: {
    Line 54: Label9.Text = "Something goes wrong…";
    Line 55: throw;
    Line 56: }
    Line 57: finally

    Source File: C:UsersLenovo1DesktopITSem-6SGPCSPIT_FeedbackCSPIT_feedbackFilesfaculty_registration_page_1.aspx.cs Line: 55

  9. Jamaal Simpson says:

    Hey, i was wondering what code would you need to make a login page that is able to take data from the sql table you made in this video ??

  10. Grishma Prabhu says:

    Thank You so much for this video

  11. Fatima Ourbat says:

    Hello ! First thank you for your efforts but what about the registration with facebook gmail and twitter

  12. gopi r says:

    Sir please tell me….how to insert values into the table

  13. Li Ying 0919 says:

    Can we make the registration system autocomplete?

  14. Li Ying 0919 says:

    Sir please help me

  15. gopi r says:

    While loging in into the login page, I have given the user name of one person and I want to see the information and data ( I mean retrieving the data )of only login user how to do that sir….. please help me

  16. Musawer Awan says:

    we can use External database ? Sql server 2012, if yes so how?

  17. MCAntMonk615 says:

    I had an error stating that

    Invalid object name 'regi' even though i had created a table. This error occurs on Registration.aspx.cs

  18. The best videos says:

    parsing "^[a-ZA-Z0-9'@&#.s]{3,10}$" – [x-y] range in reverse order. Occur this error plz solve it

  19. Devang shah says:

    hello

  20. Jason Kitts says:

    you did not show the data if it was saved in the database

  21. Amardeep Amar says:

    Sir I watch second part of this tutorial but In Web.config "File" You Did not show all whatever you coading in web.config. Can u Ellaborate,Whatever u coading in this.PLZ say how i get benifit of this tutorial of part2.

    Sir PLZ Give Me idea about web.config.

  22. Marc Reginald says:

    How to encrypt password please thank you 🙂

  23. Salman sami says:

    can it sign in through social media it works or not ?

Leave a Reply

Your email address will not be published. Required fields are marked *