Update Data Into SQL Database By using Windows Form Application


In this video tutorial we will learn how to update database record by using windows from  application. To continue with this session please watch previous video. 


Software Required :


1.Microsoft SQL Server .
2.Microsoft SQL Management Studio.
3.visual studio 2017 .  

Please share if you think these video are useful .Late video we will learn how to consume WCF ,WCF(REST) service into Angular JS Application, Windows Form Application, Console Application etc .  In this session we are trying to learn some basic knowledge about insert , update and delete operation . 
Here is what we i want do . First we need to create database in SQL server .Here is the SQL Script to Create the Database  table and insert some data  but we will be doing it by using windows form application .I already created the required table and inserted some sample data.  

we want to update user password by providing current password and the username.  

Here is How we want to design windows form application .




Just double click the Register button to generate the button event .Copy and paste following codes .


  private void button3_Click(object sender, EventArgs e)
        {
            SqlDataAdapter ASFD = new SqlDataAdapter("SELECT COUNT (*) FROM Cashir where username = '" + textBox1.Text + "' AND password='" + OldPassword.Text + "'", con);
            DataTable DS = new DataTable();
            ASFD.Fill(DS);

            if (DS.Rows[0][0].ToString() == "1")
            {
                if (NewPassword.Text == ConfarmPassword.Text)
                {
                    SqlDataAdapter cc = new SqlDataAdapter("update Cashir set password='" + NewPassword.Text + "' where Username = '" + textBox1.Text + "' and password='" + OldPassword.Text + "'", con);
                    DataTable DF = new DataTable();
                    cc.Fill(DF);
                    MessageBox.Show("Password is changed");
                    con.Close();

                }

            }
        }
If done everything correctly you will see the message box showing the message . 




No comments:

Post a Comment