public int EditaSetor(Setor s) { string sql = "UPDATE setor SET nome = @nome WHERE codSetor = @codigo;"; int result = 0; SqlConnection conn = new SqlConnection(strConnection); SqlCommand sqlcmd = new SqlCommand(sql, conn); sqlcmd.Parameters.AddWithValue("@codigo", s.GetCodSetor()); sqlcmd.Parameters.AddWithValue("@nome", s.GetNome()); try { conn.Open(); result = sqlcmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return(result); }
public int CadastraSetor(Setor s) { String sql = "INSERT INTO setor ([nome]) VALUES " + "(@nome)"; int result; SqlConnection conn = new SqlConnection(strConnection); SqlCommand sqlcmd = new SqlCommand(sql, conn); sqlcmd.Parameters.AddWithValue("@nome", s.GetNome()); try { conn.Open(); result = sqlcmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return(result); }