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