public Vacinas sp_readVacinasById(Vacinas v) { try { string procedure = "sp_readVacinasById"; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(procedure, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@id", SqlDbType.Int).Value = v.idVacina; connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { v.nomeVacina = reader[0].ToString(); } } connection.Close(); return(v); } catch (SqlException) { return(null); } }
public string sp_updateVacina(Crianca crianca, Vacinas vacinas) { try { string procedure = "sp_updateVacina"; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(procedure, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@idVacina", SqlDbType.Int).Value = vacinas.idVacina; command.Parameters.Add("@nomeVacina", SqlDbType.VarChar).Value = vacinas.nomeVacina; command.Parameters.Add("@cpf", SqlDbType.VarChar).Value = crianca.cpf; command.Parameters.Add("@quando", SqlDbType.DateTime).Value = DateTime.Now; connection.Open(); command.ExecuteNonQuery(); connection.Close(); return("Vacina alterada com sucesso!"); } catch (SqlException ex) { return("Vacina não foi alterada.\n" + ex.Message); } }