connectseekers.com

Monday, 30 March 2020

Registration Form In C# With SQL Database

3/30/2020 - By Pranav Singh 2


This article will show you how you can create registration form in c#.net with SQL database. So in this article I have used Ms SQL server database. In this I will save the user login detail into sql table by using c#.net

First we will create a windows application registration form.




Above form is a custom design registration from and you can check how to create a custom registration from in windows application.

On submit button add the below code.

private void btnSubmit_Click(object sender, EventArgs e)
        {
            string connection = @"Server=LAPTOP-EVJEKV38\SQLEXPRESS; Database=TestDB; Integrated Security=True";
            SqlConnection con = new SqlConnection(connection);
            try
            {
                string query = "Insert into UserLogin(Name,EmailId,LoginId,Password) Values('" + txtName.Text + "','" + txtEmailId.Text + "','" + txtLoginId.Text + "','" + txtpassword.Text + "')";
                SqlDataAdapter da = new SqlDataAdapter(query, con);
                con.Open();
                da.SelectCommand.ExecuteNonQuery();
                MessageBox.Show("Account created successfully..");
                ClearData();
            }
            catch
            {
                MessageBox.Show("Error occured...");
            }
            finally
            {
                con.Close();
            }
        }
        //Clear data after submit
        private void ClearData()
        {
            txtName.Text = "";
            txtEmailId.Text = "";
            txtLoginId.Text = "";
            txtpassword.Text = "";
            txtConPassword.Text = "";
        }

Here is above code I have saved the data into the database. After saving the record a message will show and later all the records have been cleared. Now let’s run the application and check the output. For this I have created a table named as UserLogin.

In above code u need to change the connection string as per your server database and change the query as per you need.

Now add the detail into form and click on submit.




Now check the data base for detail



DOWNLOAD




About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

2 comments:

  1. so short tutorial and really so dirty and full of bad-practice code

    - do you really wanna CATCH everything!?
    - keeping sql connection string in method!?
    - sql injection - use parametrized query instead concating strings LOL

    ReplyDelete
    Replies
    1. Thanks for you valuable comment. This is for beginners and i don't think keeping code simple cause any harm. But still your idea is really good i will take care of it.
      Thanks

      Delete

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top