String or binary data would be truncated. The statement has been terminated. - Explanation

Couple of days ago I was facing this issue while saving my table data using Entity Framework in C#. After reviewing my code and data base table design, I have realized that what the mistake I made. I was trying to insert 8 char length of string into 'Code' column of 'Employee' table.


This error occurs when we try to insert the string type of data which is more size than the actual column size.

This is not only the error which is thrown by Entity Framework. Entity Framework converts your linq query into SQL based query format and executes it upon calling .SaveChanges() method on entity object. So same error will definitely throw even with the regular SQL statement, where it is trying to insert a string type of data which is more than the column size.

To be explain more about this error:
"String or binary data would be truncated." - The data which you are inserting would be truncated as its size is more than the actual column size.
"The statement has been terminated." - Due to above error in your query, the SQL statement has been terminated without executing in database.

The only solution to resolve this error is, maintaining the size of column more than the size of data which you are inserting into that column.

Hope this helps! Have any questions on this? Let’s use the comment box below.
String or binary data would be truncated. The statement has been terminated. - Explanation String or binary data would be truncated. The statement has been terminated. - Explanation Reviewed by Dotnet 4 Techies on March 1, 2015 10:57 AM Rating: 5

1 comment:

  1. sir same error is coming my website and i check my database but not my database is correctly sir please gime solutin

    ReplyDelete

Powered by Blogger.