コード例 #1
0
        public bool AddMedicines(Medicines newMed)
        {
            try
            {
                using var connection = new MySqlConnection(connectionString);
                connection.Open();
                using var command = new MySqlCommand("INSERT INTO medicines (name, rating, price) VALUES (@name, @rating, @price);", connection);
                command.Parameters.AddWithValue("@name", newMed.Name);
                command.Parameters.AddWithValue("@rating", newMed.Rating);
                command.Parameters.AddWithValue("@price", newMed.Price);

                command.ExecuteNonQuery();
                connection.Close();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
コード例 #2
0
        public bool EditMedByName(Medicines newMed, string Name)
        {
            try
            {
                using var connection = new MySqlConnection(connectionString);
                connection.Open();
                using var command = new MySqlCommand("UPDATE medicines SET name=@name, rating=@rating, price=@price WHERE name=@Name_in;", connection);
                command.Parameters.AddWithValue("@name", newMed.Name);
                command.Parameters.AddWithValue("@rating", newMed.Rating);
                command.Parameters.AddWithValue("@price", newMed.Price);
                command.Parameters.AddWithValue("@Name_in", Name);

                command.ExecuteNonQuery();
                connection.Close();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }