String or binary data would be truncated

Asked

Viewed 9,606 times

1

This error occurs when I try to run my trial, I don’t know why it 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.

1 answer

4

This error occurs when you try to insert a higher value in a field than was set to it at the time of its creation.

For example:

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

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

INSERT INTO TESTE( 1, '123456' )

I get this mistake:

inserir a descrição da imagem aqui

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.