Update & Delete data from database (C#)

Add two button "Update" & "Delete"

In hear i added icon image to my button for it's look like better..

To add a image go to Properties , Image


Click "Import" & choose your icon. Then click OK.



Icon will add to button. But it's not looks like better..

Go to Properties ,ImageAlign, & set it as MiddleLeft.

Now it's look like better.


Now add this codes

Update
string conString = "datasource=localhost;port=3306;username=root;password=";
            string Query = "update  blog.empdata set  FName='" + this.txtFName.Text + "',LName='" + this.txtLName.Text + "',Age='" + this.txtAge.Text + "'where FName='" + this.txtFName.Text + "';";
            MySqlConnection conDataBase = new MySqlConnection(conString);
            MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
            MySqlDataReader myReader;
            try
            {
                conDataBase.Open();
                myReader = cmdDataBase.ExecuteReader();
                MessageBox.Show("Updated");
                while (myReader.Read())
                {

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Delete
 string conString = "datasource=localhost;port=3306;username=root;password=";
            string Query = "delete from  blog.empdata where FName='" + this.txtFName.Text + "';";
            MySqlConnection conDataBase = new MySqlConnection(conString);
            MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
            MySqlDataReader myReader;
            try
            {
                conDataBase.Open();
                myReader = cmdDataBase.ExecuteReader();
                MessageBox.Show("Deleted");
                while (myReader.Read())
                {

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


            }

2 comments: