Exemple #1
0
        private void button5_Click(object sender, EventArgs e)
        {
            this.Hide();
            UpdateUser f1 = new UpdateUser();

            f1.ShowDialog();
            this.Close();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string connectionString = "SERVER=" +
                                      DBConnect.SERVER + ";" + "DATABASE=" +
                                      DBConnect.DATABASE_NAME + ";" + "UID=" +
                                      DBConnect.USER_NAME + ";" + "PASSWORD="******";" + "SslMode=" +
                                      DBConnect.SslMode + ";";
            MySqlConnection myConnection = new MySqlConnection(connectionString);

            try
            {
                {
                    String query =
                        "UPDATE users SET Firstname = @prm_FirstName, LastName = @prm_LastName, Gender = @prm_Gender, HomeTown = @prm_HomeTown, HomeCity = @prm_HomeCity, CurrentTown = @prm_CurrentTown, CurrentCity = @prm_CurrentCity, RelationshipStatus = @prm_RelationshipStatus " +
                        "WHERE UserID = " + tbuserid.Text + "";

                    myConnection.Open();
                    MySqlCommand     cmd   = new MySqlCommand(query, myConnection);
                    MySqlDataAdapter sqlDA = new MySqlDataAdapter(cmd);


                    cmd.Parameters.AddWithValue("@prm_FirstName", tbfirstname.Text);
                    cmd.Parameters.AddWithValue("@prm_LastName", tblastname.Text);
                    cmd.Parameters.AddWithValue("@prm_Gender", cbgender.Text);
                    cmd.Parameters.AddWithValue("@prm_HomeTown", tbhometown.Text);
                    cmd.Parameters.AddWithValue("@prm_HomeCity", tbhomecity.Text);
                    cmd.Parameters.AddWithValue("@prm_CurrentTown", tbcurrenttown.Text);
                    cmd.Parameters.AddWithValue("@prm_CurrentCity", tbcurrentcity.Text);
                    cmd.Parameters.AddWithValue("@prm_RelationshipStatus", cbrelationshipstatus.Text);


                    cmd.ExecuteNonQuery();
                }
                MessageBox.Show("User " + tbuserid.Text + " updated!");
                this.Hide();
                UpdateUser f1 = new UpdateUser();
                f1.ShowDialog();
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("User not updated, Please try again");
            }
        }