Exemple #1
0
        //Delete data
        protected void Delete(Label Id, addBrand suspend)
        {
            try
            {
                conn = new MySqlConnection(this.connection());
                conn.Open();
                DialogResult result = MessageBox.Show("Do you want to Delete this data?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    command = new MySqlCommand("DELETE FROM brand WHERE brand_id = @brand_id", conn);
                    command.Parameters.AddWithValue("@brand_id", Id.Text);

                    bool isCheck = (int)command.ExecuteNonQuery() > 0;

                    if (isCheck == true)
                    {
                        MessageBox.Show("Successfully Deleted", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        suspend.Hide();
                    }

                    command.Dispose();
                    conn.Close();
                }
                else
                {
                    MessageBox.Show("Your Data is safe", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
        //Update Data
        protected void update(TextBox text, Label Id, addBrand suspend)
        {
            try
            {
                conn = new MySqlConnection(this.connection());
                conn.Open();
                command = new MySqlCommand("UPDATE brand SET brand_name = @brand_name, date_updated = @date_updated WHERE brand_id = @brand_id", conn);
                command.Parameters.AddWithValue("@brand_name", text.Text);
                command.Parameters.AddWithValue("@date_updated", dateNow);
                command.Parameters.AddWithValue("@brand_id", Id.Text);

                bool result = (int)command.ExecuteNonQuery() > 0;

                if (result == true)
                {
                    MessageBox.Show("Updated Successfully", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    suspend.Hide();
                }

                text.Clear();

                conn.Close();
                command.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }