public void InserirTrainee(Trainee trainee) { SqlConnection cx = new SqlConnection(ConnectionString); try { string cmd = "insert into Trainee (Nome) values (@Nome)"; SqlCommand sc = new SqlCommand(cmd, cx); sc.Parameters.AddWithValue("@Nome", trainee.Nome); cx.Open(); sc.ExecuteNonQuery(); } finally { cx.Close(); } }
public void AtualizarTraineePorID(int id, Trainee c) { SqlConnection cx = new SqlConnection(ConnectionString); try { string cmd = "update Trainee set Nome = @newName where Id = @id"; SqlCommand sc = new SqlCommand(cmd, cx); sc.Parameters.AddWithValue("@id", id); sc.Parameters.AddWithValue("@newName", c.Nome); cx.Open(); sc.ExecuteNonQuery(); } finally { cx.Close(); } }
private static void InserirTraineeEF(TraineeRepositorioEF traineedb) { Trainee newTrainee = new Trainee("Pedro Lucas"); traineedb.InserirTrainee(newTrainee); }