I encountered a small detail problem today and found it to be a long time.
String STR = "a.2104697aa (Wuhu jinaorui) B .2104697ba (Changsha Bosch )";
Str. Length = 40
In C #, the length of string STR is 40. Here it refers to the length of string.
If STR varchar (50) is inserted into the SQL database, the following error occurs: string or binary data wocould be truncated. If the string length is too long, it must be truncated.
Then, the result of the select Len ('A. 2104697aa (Wuhu jiangrui) B .2104697ba (Changsha Bosch) ') query is 40, which indicates that the length is not exceeded.
After searching, we found that the query result of select datalength ('A. 2379697aa (Wuhu jinaorui) B .2379697ba (Changsha Bosch) 'is 52.
Datalength: returns the length of the string in bytes.
Len: returns the length of characters.
The length of varchar refers to the length of the string in bytes.
Appendix: differences between varchar nvarchar char
From: http://www.cnblogs.com/yelaiju/archive/2010/05/29/1746826.html
Character length or Byte Length