public void Update(Camadas.Model.Servico servico) { SqlConnection conexao = new SqlConnection(strCon); string sql = "Update Servico set descricao=@descricao, valorServ=@valorServ where id=@id"; SqlCommand cmd = new SqlCommand(sql, conexao); cmd.Parameters.AddWithValue("@id", servico.id); cmd.Parameters.AddWithValue("@descricao", servico.descricao); cmd.Parameters.AddWithValue("@valorServ", servico.valorServ); try { conexao.Open(); cmd.ExecuteNonQuery(); } catch { Console.WriteLine("Erro - Update do Servico"); } finally { conexao.Close(); } }
public void Insert(Camadas.Model.Servico servico) { SqlConnection conexao = new SqlConnection(strCon); string sql = "Insert into Servico values (@descricao, @valorServ)"; SqlCommand cmd = new SqlCommand(sql, conexao); cmd.Parameters.AddWithValue("@id", servico.id); cmd.Parameters.AddWithValue("@descricao", servico.descricao); cmd.Parameters.AddWithValue("@valorServ", servico.valorServ); try { conexao.Open(); cmd.ExecuteNonQuery(); } catch { Console.WriteLine("Erro - insert do Servico"); } finally { conexao.Close(); } }