---
title: "How to make reset form with the help of c# and sql server"  
description: "How to make reset form with the help of c# and sql server"  
author: "Ailsa Singh"  
published: 2016-10-21  
updated: 2016-10-21  
canonical: https://www.mindstick.com/forum/34197/how-to-make-reset-form-with-the-help-of-c-sharp-and-sql-server  
category: "c#"  
tags: ["c#", "sql server", "sql"]  
reading_time: 3 minutes  

---

# How to make reset form with the help of c# and sql server

Hi Guys\
I need to make reset [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) with the help of c# and [sql server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server).Which include [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) id ,old [password](https://www.mindstick.com/blog/118/retriving-user-password-by-using-stored-procedure-in-asp-dot-net),new password and hint.\
i need to show [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) massege for all possible error like password mismatch etc.\
I would really appreciate your help\
Thanks\
\
\
\

## Replies

### Reply by Abhishek Srivasatava

Hi Alisha,\
I have created similar form during my training period, it may help you.\
\
![How to make reset form with the help of c# and sql server](https://www.mindstick.com/mindstickforums/b43ae12c-77f3-4225-b8a1-091e4205044a/images/78045441-7d6d-4afc-94a5-db4b14f93cf3.png)\
\
Before going to coding part you need to create table which include all above item. I have developed the logic with the help of store procedure.\
\
I have created store procedure \

```
Create PROCEDURE User_Info(@UserId varchar(50),@Old_Password varchar(50),@New_Password varchar(50),@confirm_new_password varchar(50),@Password_Hint varchar(50)) ASBEGIN          IF NOT EXISTS (SELECT UserId FROM User_information                         
where 
UserId = @UserId)                     BEGIN                              
PRINT 'No Such
UserId Exist'                     END        ELSE        begin           declare @checkpass varchar(30);                             set     @checkpass= (SELECT User_Password
FROM User_information where  UserId =
@UserId)                                                          if (@Checkpass<> @Old_Password)                                                          begin                                                          print 'old password is wrong'                                                          end                                                                                                                    ELSE                                                                  IF (@New_Password <> @confirm_new_password)                                                                                      BEGIN                                                                                      PRINT 'Password doesn''t
match'                                                                                      END                                                                             ELSE                                                                                      BEGIN                                                                                      UPDATE 
User_information                          SET User_Password=
@confirm_new_password , Password_Hint= @Password_Hint                                                                                      WHERE UserId =
@UserId                                                                             END                   END   END
```

\

Here is the complete code for the reset form:

```
 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace FormsApplication1{    public partial class Form3 : Form    {        public Form3()        {            InitializeComponent();        }         private void button1_Click(object sender, EventArgs e)        {            SqlConnection con = new SqlConnection();            con.ConnectionString = (@"Data Source=msclient-012\sqlexpress;Initial Catalog=testing_st;User ID=sa;Password=mindstick");            con.Open();            SqlCommand cmdreset = new SqlCommand("User_Info", con);            cmdreset.Connection = con;            cmdreset.CommandType = CommandType.StoredProcedure;            cmdreset.Parameters.AddWithValue("@Old_Password", textBox1.Text);            cmdreset.Parameters.AddWithValue("@UserId", textBox5.Text);            cmdreset.Parameters.AddWithValue("@New_Password", textBox2.Text);            cmdreset.Parameters.AddWithValue("@confirm_new_password", textBox3.Text);            cmdreset.Parameters.AddWithValue("@Password_Hint", textBox4.Text);             if (textBox5.Text.Trim() == string.Empty)            {                MessageBox.Show("Userid required","Warning Message");             }            else            {                if(textBox1.Text.Trim() == string.Empty)                {                    MessageBox.Show("Old Password Required!!","Warning Message");                 }                else                {                    if(textBox2.Text.Trim() == string.Empty)                    {                        MessageBox.Show("New password required","Warning Message");                    }                    else                    {                        if (textBox3.Text.Trim() == string.Empty)                        {                            MessageBox.Show("Confirm Password Required","Warning Message");                        }                        else                        {                           
cmdreset.ExecuteNonQuery();                            SqlCommand cmd = new SqlCommand("Select UserId from User_information where UserId=@UserId and User_Password=@User_Password", con);                            //   SqlCommand cmd = new
SqlCommand("Login_Check_Sp", con);                            // cmd.CommandType =
CommandType.StoredProcedure;                            DataTable dt = new DataTable();                            cmd.Parameters.AddWithValue("@UserId", textBox5.Text);                           
cmd.Parameters.AddWithValue("@User_Password", textBox2.Text);                            SqlDataReader read = cmd.ExecuteReader();                            read.Read();                             if (read.HasRows)                            {                                MessageBox.Show("Successfully changed the Password ","Contrats Message");                                read.Close();                                this.Close();                            }                            else                            {                                read.Close();                                 SqlCommand cmd1 = new SqlCommand("Select UserId from User_information where UserId=@UserId and User_Password=@User_Password", con);                                //   SqlCommand cmd = new
SqlCommand("Login_Check_Sp", con);                                // cmd.CommandType =
CommandType.StoredProcedure;                                DataTable dt1 = new DataTable();                               
cmd1.Parameters.AddWithValue("@UserId", textBox5.Text);                                cmd1.Parameters.AddWithValue("@User_Password", textBox1.Text);                                SqlDataReader read1 =
cmd1.ExecuteReader();                                read1.Read();                                 if (read1.HasRows)                                {                                    //here you may
redirect to another page like Response.Redirect("Page2.aspx");                                    MessageBox.Show("Password mismatich ","Warning Message");                                    read1.Close();                                 }                                else                                {                                    MessageBox.Show("Old Password is wrong","Warning Message");                                }                            }                                                         con.Close();                                                   }                    }                }            }        }                      private void button2_Click  (object sender, EventArgs e)        {            this.Close();        }         private void textBox1_TextChanged(object sender, EventArgs e)        {            textBox1.PasswordChar = '*';            textBox1.MaxLength = 8;        }         private void textBox2_TextChanged(object sender, EventArgs e)        {            textBox2.PasswordChar = '*';            textBox2.MaxLength = 8;        }         private void textBox3_TextChanged(object sender, EventArgs e)        {            textBox3.PasswordChar = '*';            textBox3.MaxLength = 8;        }     }}
```

\


---

Original Source: https://www.mindstick.com/forum/34197/how-to-make-reset-form-with-the-help-of-c-sharp-and-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
