Error appearing:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: Error converting data type varchar to int.
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;
}
Procedure:
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