Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public static string CriarPessoa(string procedureName, string tableName, string nome, double cpf)
  2. {
  3.  
  4. string returnStringOutput;
  5.  
  6. SqlCommand sqlComando = ConexaoComParametro(procedureName);
  7.  
  8. sqlComando.Parameters.Add(new SqlParameter("@nome", nome));
  9. sqlComando.Parameters.Add(new SqlParameter("@cpf", cpf));
  10. sqlComando.Parameters.Add(new SqlParameter("@outputmsg", DbType.String)).Direction = ParameterDirection.Output;
  11.  
  12. SqlParameter outputmsg = sqlComando.Parameters.Add("@ouputmsg", DbType.String);
  13. outputmsg.Direction = ParameterDirection.ReturnValue;
  14. sqlComando.ExecuteNonQuery();
  15.  
  16. returnStringOutput = (string)sqlComando.Parameters["@ouputmsg"].Value;
  17.  
  18.  
  19.  
  20. return returnStringOutput;
  21.  
  22. }
  23.  
  24. ALTER PROCEDURE [dbo].[sp_c_funcionario]
  25.  
  26. @operacao [char](1),
  27. @nome [varchar](20),
  28. @cpf [bigint],
  29. @outputmsg [varchar](50) OUTPUT
  30.  
  31. AS
  32.  
  33. IF EXISTS (SELECT 1 FROM [dbo].[Funcionario] WHERE [cpf]=@cpf)
  34. BEGIN
  35.  
  36. SET @outputmsg = 'Lamento, mas esse CPF já existe'
  37.  
  38. END
  39. ELSE
  40. BEGIN
  41.  
  42.  
  43. IF @operacao='c'
  44. BEGIN
  45. INSERT INTO [dbo].[Funcionario] ([nome], [cpf])
  46. VALUES (@nome,@cpf)
  47.  
  48. END
  49.  
  50.  
  51. END
  52.  
  53.  
  54. RETURN
  55.  
  56.  
  57. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement