public void UpdateDataCadastroTeste(CadastroTeste cadastroteste) { string connectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=Teste;" + "Integrated Security=true"; // Provide the query string with a parameter placeholder. string queryString = "UPDATE CadastroTeste SET Id = @Id, Descricao = @Descricao WHERE Id = @Id"; // Create and open the connection in a using block. This // ensures that all resources will be closed and disposed // when the code exits. using (SqlConnection connection = new SqlConnection(connectionString)) { // Create the Command and Parameter objects. SqlCommand cmd = new SqlCommand(queryString, connection); // Open the connection in a try/catch block. // Create and execute the DataReader, writing the result // set to the console window. try { cmd.Parameters.Add("@Id", SqlDbType.Int).Value = cadastroteste.Id; cmd.Parameters.Add("@Descricao", SqlDbType.VarChar, 50).Value = cadastroteste.Descricao; connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } catch (Exception ex) { throw ex; } } }
public void Put(CadastroTeste cadastroTeste) { var repository = new CadastroTesteDAO(); repository.UpdateDataCadastroTeste(cadastroTeste); }