public bool Update(Infecoes i) { bool isSucess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "UPDATE infecoes SET nome=@nome, sintomas=@sintomas WHERE id = @id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@nome", i.Nome); cmd.Parameters.AddWithValue("@sintomas", i.Sintomas); cmd.Parameters.AddWithValue("@id", i.Id); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSucess = true; } else { isSucess = false; } } catch (Exception ex) { } finally { conn.Close(); } return(isSucess); }
// Inserir infecoes na tabela public bool Insert(Infecoes i) { bool isSucess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "INSERT INTO infecoes (nome, sintomas) VALUES(@nome, @sintomas)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@nome", i.Nome); cmd.Parameters.AddWithValue("@sintomas", i.Sintomas); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSucess = true; } else { isSucess = false; } } catch (Exception ex) { } finally { conn.Close(); } return(isSucess); }