예제 #1
0
        public void Alterar(Bebidac b)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection())
                {
                    conn.ConnectionString = strConexao;
                    conn.Open();

                    using (SqlCommand command = new SqlCommand())
                    {
                        string query = "Update dbo.Bebida set nome=@nome,tamanho=@tamanho,preco=@preco where id=@id";
                        command.CommandText = query;
                        command.Connection  = conn;
                        command.Parameters.AddWithValue("@nome", b.Nome);
                        command.Parameters.AddWithValue("@tamanho", b.Litros);
                        command.Parameters.AddWithValue("@preco", b.Preco);
                        command.Parameters.AddWithValue("@id", b.Id);
                        command.ExecuteNonQuery();
                    }
                }
                MessageBox.Show("Bebida " + b.Nome + " alterada com sucesso!");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public void Excluir(Bebidac b)
        {
            try
            {
                using (SqlConnection conexao = new SqlConnection())
                {
                    conexao.ConnectionString = strConexao;
                    conexao.Open();

                    using (SqlCommand comando = new SqlCommand())
                    {
                        string strSql = "Delete Bebida where id=@id";
                        comando.CommandText = strSql;
                        comando.Connection  = conexao;
                        comando.Parameters.AddWithValue("@id", b.Id);
                        comando.ExecuteNonQuery();
                    }
                }
                MessageBox.Show("Bebida deletada com sucesso!");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        public void Incluir(Bebidac b)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection())
                {
                    conn.ConnectionString = strConexao;
                    conn.Open();

                    using (SqlCommand command = new SqlCommand())
                    {
                        string query = "Insert into dbo.Bebida(nome,tamanho,preco) values(@nome, @tamanho, @preco)";
                        command.CommandText = query;
                        command.Connection  = conn;
                        command.Parameters.AddWithValue("@nome", b.Nome);
                        command.Parameters.AddWithValue("@tamanho", b.Litros);
                        command.Parameters.AddWithValue("@preco", b.Preco);
                        command.ExecuteNonQuery();
                    }
                }
                MessageBox.Show("Bebida cadastrada com sucesso!");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }