Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. public static int fn_insertaActualizaPaginas(int ai_codigoPagina, int ai_codigoPerfil, bool ab_estaActivo)
  2. {
  3. int li_respuesta = 0;
  4. try
  5. {
  6. using (TransactionScope ts = new TransactionScope())
  7. {
  8. SqlConnection con = new SqlConnection(Metodo.dameConexionBDD);
  9. con.Open();
  10.  
  11. {
  12. String sql = " BEGIN " +
  13. " MERGE SI_MENU_PERFIL AS Target " +
  14. " USING ( SELECT @CODIGO_PUS CODIGO_PUS, " +
  15. " @CODIGO_PAG CODIGO_PAG, " +
  16. " @ESTAACTIVO_MPE ESTAACTIVO_MPE " +
  17. " ) AS Source " +
  18. " ON (Target.CODIGO_PUS = Source.CODIGO_PUS AND Target.CODIGO_PAG = Source.CODIGO_PAG) " +
  19. " WHEN MATCHED THEN " +
  20. " UPDATE SET Target.ESTAACTIVO_MPE = Source.ESTAACTIVO_MPE " +
  21. " WHEN NOT MATCHED BY TARGET THEN " +
  22. " INSERT (CODIGO_PUS, CODIGO_PAG, ESTAACTIVO_MPE) " +
  23. " VALUES (Source.CODIGO_PUS, Source.CODIGO_PAG, Source.ESTAACTIVO_MPE); " +
  24. " END ";
  25.  
  26. SqlCommand cmd = new SqlCommand(sql, con);
  27. cmd.CommandType = CommandType.Text;
  28.  
  29. cmd.Parameters.Add("@CODIGO_PUS", SqlDbType.Int).Value= ai_codigoPerfil;
  30. cmd.Parameters.Add("@CODIGO_PAG", SqlDbType.Int).Value= ai_codigoPagina;
  31. cmd.Parameters.Add("@ESTAACTIVO_MPE", SqlDbType.Bit).Value= ab_estaActivo;
  32.  
  33. li_respuesta = Convert.ToInt32(cmd.ExecuteNonQuery());
  34.  
  35. if (ai_codigoPagina > 0)
  36. li_respuesta = ai_codigoPagina;
  37. }
  38. con.Close();
  39. ts.Complete();
  40. }
  41. }
  42. catch (Exception err)
  43. {
  44. throw err;
  45. }
  46. return li_respuesta;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement