简体   繁体   English

更新语句中的“字符串或二进制数据将被截断”

[英]“String or binary data would be truncated” in update statement

I have the following code: 我有以下代码:

glat += result.geometry.location.lat;
glong += result.geometry.location.lng;
gPostal += postalCode;    

sqlUpdateQuery = "update testlatlong set Lat =@lat,Long =@long where postalcode =@postal";
SqlCommand updateCommand = new SqlCommand(sqlUpdateQuery, sqlConn);
updateCommand.Parameters.Add("@lat", SqlDbType.NVarChar).Value = glat;
updateCommand.Parameters.Add("@long", SqlDbType.NVarChar).Value = glong;
updateCommand.Parameters.Add("@postal", SqlDbType.NVarChar).Value = gPostal;
updateCommand.ExecuteNonQuery();

I kept encountering the issue: "string or binary data would be truncated. The statement has been terminated". 我一直遇到问题:“字符串或二进制数据将被截断。该语句已终止”。 The column types for my lat and long are nvarchar(max) in my sql tables. 我的lat和long的列类型是sql表中的nvarchar(max) What could be the issue in my case? 我的情况可能是什么问题?

It is going to be these lines: 将是这些行:

glat += result.geometry.location.lat;
glong += result.geometry.location.lng;
gPostal += postalCode;    

They just look wrong. 他们看起来错了。 All the code you posted look like they are in a loop, for which the postal code will keep growing due to +=, eventually being longer than the size of the column. 您发布的所有代码看起来都处于循环中,由于+ =,邮政编码将持续增长,最终会比列的长度还要长。

Even if the lat and lng are varchar(max), what's it doing incrementally adding to the column value? 即使lat和lng是varchar(max),将增量添加到列值的操作是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM