Link to home
Start Free TrialLog in
Avatar of rckrch
rckrchFlag for United States of America

asked on

Data entry into sql server. string or binary data would be truncated.

I get the following error and I don't know why.  I am using sql server and defined my data as nvarchar(10).  I am only trying to enter one character in the column and I get the error.  I have also tried using char as the data type.  I have some null values in the columns.

Can anyone help?

Thanks,

String or binary data would be truncated.
The statement has been terminated.
ASKER CERTIFIED SOLUTION
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Maybe you're inserting the wrong value. double check your code.
Avatar of rckrch

ASKER

FRTableConCommand.CommandText = "UPDATE FR_CELLCOLOR SET ContBreakPoint=@ContBreakPoint WHERE CustomerConcernNo=@CustomerConcernNo"
            FRTableConCommand.Parameters("@ContBreakPoint").Value = "R"
            FRTableConCommand.Parameters("@CustomerConcernNo").Value = "1004"
            FRTableConCommand.ExecuteNonQuery()

"ContBreakPoint" data type  is nvarchar(10) in sql server.

The above code gives me the error.
You should be adding the parameters -
FRTableConCommand.CommandText = "UPDATE FR_CELLCOLOR SET ContBreakPoint=@ContBreakPoint WHERE CustomerConcernNo=@CustomerConcernNo"
FRTableConCommand.Parameters.Add("@ContBreakPoint").Value = "R"
FRTableConCommand.Parameters.Add("@CustomerConcernNo").Value = "1004"
FRTableConCommand.ExecuteNonQuery()

Open in new window

-saige-
Avatar of rckrch

ASKER

The parameters were added in a previous statement.  There parameters are revised for the same update statement because they are in a loop.  The loop searches for condition in a grid view across several cells.
I would look at FR_CELLCOLOR in SSMS. Is it a view or table? Does it has an [INSTEAD OF] UPDATE trigger? When it is a view, do the base tables have such triggers?
Avatar of rckrch

ASKER

It is not a view it is a table.  it does not use an [INSTEAD OF] UPDATE trigger.

Also, I found the issue.  As I said with my initial post I have null values in some of  the columns in the table.  Due to the loop and the condition the procedure is looking for some of the values during the update could also be null.  This is when I get the error.
Avatar of rckrch

ASKER

Just increased the nvarchar from 10 to 25.  that solved the problem.