1
Error that appears:
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
What is the line of error in the code
C#
?– novic
@israel3D - The sp_c_funcionario procedure has 3 input parameters: @operation, @ name and@Cpf. It seems to me that the first parameter, @operation, was not reported. I could check?
– José Diz
@israel3D - In the Funcio table, how is the Cpf column declared? The error message, returned by SQL Server, is "Error Converting data type varchar to int". In the Creat Person procedure, the Cpf parameter would not be Int64?
– José Diz
No error noted in the code, only in the return of the bank @Virgilionovic
– israel3D
Actually @Josédiz, missed the operation. But in the code is right, it was only a copy/Paste error when publishing the question. And the error itself is that it does not return my output. All parameters arrive correctly in the past.
– israel3D