umeshinator

umeshinator

  • NA
  • 1
  • 1.6k

Problem in updating password field in C# form in SQL db via code in C#.net?

Aug 12 2012 2:33 PM
Hello,guys 
 
I was just playing around c#.net as a new student,i did wanted to make billing system and initially i tried with updating/changing password of the username,scene is when user logins ,entering his/her username password,then there is a option to change the password via settings like in general yahoo,hotmail change password system.i hab sql db and it is connected but when i try to change the password it doesnt shows error,message says "it has been change" but when i check db password remains same, it doesnt change,like when i try to change the password of username:login whose present password is login1 to login2 ,it doesnt change.
 
The other fields in the form are username,password ,new password,confirm password,and the coe shown below is the update button click event.
 
Here is the coding I have done. Help me i couldnt trace the mistake/error.
 

namespace Restaurant_Billing 
{
    public partial class changepassword : Form
    {
        public changepassword()
        {
            InitializeComponent();
        }
        SqlConnection cn = new SqlConnection();
        SqlCommand cm = new SqlCommand();
        
 
        private void button2_Click(object sender, EventArgs e)
        {
               Close();
                     
        }
 

        private void button1_Click(object sender, EventArgs e) //updating the new [
        {
            txtusername.Text = globalclass.m_globalvar;
            txtpasscurrent.Text = globalclass.m_globalvar;
 
            string username = txtusername.Text;
            string password = txtpasscurrent.Text;
            string newpassword = textpassnew.Text;
            string confirmnewpassword = textpassconfirm.Text;
            if (textpassnew.Text == textpassconfirm.Text)
            {
                cm = new SqlCommand("update tbluser set Pw = '" + textpassnew.Text + "' where U_name = '" + txtusername.Text + "'");
                cm.Connection = cn;
                cm.ExecuteNonQuery();
                MessageBox.Show("password has been changed");
            }
            else
            {
                MessageBox.Show("some errors!! dawg correct it!!");
                txtpasscurrent.Focus();
            }
        }
 
            private void changepassword_Load(object sender, EventArgs e)
        {
            this.txtusername.Text = globalclass.m_globalvar;
            cn = new SqlConnection(@"server=UMESHINATOR-PC\SQLEXPRESS;integrated security=true;database=nec");
            cn.Open();
        }
    }
}

Answers (1)