Friday, May 14, 2010

String or Binary Data Would Be Truncated Error, LINQ

Error: String or Binary Data Would Be Truncated.

Desc:
Generally this error occurs when we are trying to inser/update large value in SQL server table that are not fit into columns lenght of table.

In one scenario i experienced the following scenario:

I had the one enum like below:
public enum MyEnum
{ First = 101, Second=102, Sixth=103)

now I was using this enum like MyEnum.First and assigning to the one variable
But when i was trying to insert that entity in database using LINQ i was getting the above error:


After doing debugging, I've to do following changes

var myvar = (int) MyEnum.First;

The above statement will return the 101,

that's it for now.

No comments: