Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string CriarPessoa(string procedureName, string tableName, string nome, double cpf)
- {
- string returnStringOutput;
- SqlCommand sqlComando = ConexaoComParametro(procedureName);
- sqlComando.Parameters.Add(new SqlParameter("@nome", nome));
- sqlComando.Parameters.Add(new SqlParameter("@cpf", cpf));
- sqlComando.Parameters.Add(new SqlParameter("@outputmsg", DbType.String)).Direction = ParameterDirection.Output;
- SqlParameter outputmsg = sqlComando.Parameters.Add("@ouputmsg", DbType.String);
- outputmsg.Direction = ParameterDirection.ReturnValue;
- sqlComando.ExecuteNonQuery();
- returnStringOutput = (string)sqlComando.Parameters["@ouputmsg"].Value;
- return returnStringOutput;
- }
- ALTER PROCEDURE [dbo].[sp_c_funcionario]
- @operacao [char](1),
- @nome [varchar](20),
- @cpf [bigint],
- @outputmsg [varchar](50) OUTPUT
- AS
- IF EXISTS (SELECT 1 FROM [dbo].[Funcionario] WHERE [cpf]=@cpf)
- BEGIN
- SET @outputmsg = 'Lamento, mas esse CPF já existe'
- END
- ELSE
- BEGIN
- IF @operacao='c'
- BEGIN
- INSERT INTO [dbo].[Funcionario] ([nome], [cpf])
- VALUES (@nome,@cpf)
- END
- END
- RETURN
- GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement