String or binary data would be truncated

0

This error occurs when I try to execute my procedure, I do not know why this happens.

My code:

    Dim con As SqlConnection = New SqlConnection()
        Dim cmd As SqlCommand = New SqlCommand()
        Try
            con.ConnectionString = "Server = 10.230.11.43;Database=GFT_CAD;User Id=sa;Password = qweasd;"

            con.Open()
            cmd.Connection = con
            cmd = New SqlCommand("prdInserirDocDB", con)
            cmd.CommandType = CommandType.StoredProcedure


 cmd.Parameters.Add(New SqlParameter("@SITUACAO_CACS", SqlDbType.VarChar)).Value = SITUACAO_CACS
            cmd.Parameters.Add(New SqlParameter("@CGC_CPF_PORTADOR", SqlDbType.VarChar)).Value = CGC_CPF_PORTADOR
            cmd.Parameters.Add(New SqlParameter("@FONE_CEL_PORT", SqlDbType.VarChar)).Value = FONE_CEL_PORT

            cmd.ExecuteNonQuery()
            MsgBox("inserido com sucesso")
        Catch ex As Exception
            MsgBox("erro em: " & ex.Message)

My prodecure:

@VR_ULT_PAGTO  DECIMAL(09,2) ,
@VR_PRINCIPAL  DECIMAL(09,2) ,
@SITUACAO_CACS  VARCHAR(03) ,
@CGC_CPF_PORTADOR VARCHAR(15),
@FONE_CEL_PORT VARCHAR(17) 

as 
Begin

insert into tCImp_Doc(
SDO_ATUAL,
SDO_PARC_PEND,
SDO_LEGADO,
DT_ULT_PAGTO,
VR_ULT_PAGTO,
SITUACAO_CACS,
CGC_CPF_PORTADOR,
FONE_CEL_PORT 
 )
 values(
@SDO_PARC_PEND,
@SDO_LEGADO,
@DT_ULT_PAGTO,
@VR_ULT_PAGTO,
@SITUACAO_CACS,
@CGC_CPF_PORTADOR,
@FONE_CEL_PORT

 )
 end

Ignore the wrong fields my code has many fields did not want to put all.

    
asked by anonymous 03.03.2017 / 17:05

1 answer

2

This error occurs when you attempt to enter a value greater than one that was set to it at the time it was created.

For example:

CREATE TABLE TESTE ( 
   id int,
   descr varchar(5))

If I try to enter 6 characters or more in a field set to accept only 5 .

INSERT INTO TESTE( 1, '123456' )

I get this error:

Here I used a varchar field, but the same goes for any type of field. This is why the message is generic and speaks in String or Binary data .

    
03.03.2017 / 17:28