我在第65行收到错误,我正在使用sql2008 ..我经常在executioncalar cmd上得到这个错误。你可以帮我解决.. [英] I am getting error in line 65,i am using sql2008..and i frequently get this error on executescalar cmd..can u pls help me out..

查看:66
本文介绍了我在第65行收到错误,我正在使用sql2008 ..我经常在executioncalar cmd上得到这个错误。你可以帮我解决..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.



来源错误:


Source Error:

 63  con.Close();
 64  con.Open();
 65  int result = (Int32)cmd2.ExecuteScalar();
 66  con.Close();

推荐答案

所有这意味着您尝试将数据插入(或更新)到已修复的字段长度,以及您传递的数据不适合。

例如,如果您的表具有nChar(10)的UserName列,并且您插入''MikeyJones''那么它将起作用,但''MikeyXJones''会导致字符串或二进制数据被截断。错误,因为11个字符不适合。



在修改数据库数据之前检查并截断,或者扩大列数据大小。
All it means is that you are trying to insert (or update) data to a field that has a fixed length, and the data you are passing does not fit.
For example, if your table has a UserName column that is nChar(10), and you insert ''MikeyJones'' then it will work, but ''MikeyXJones'' will cause a "String or binary data would be truncated." error as eleven character will not fit.

Either check and truncate before you modify the database data, or enlarge the column data size.


这篇关于我在第65行收到错误,我正在使用sql2008 ..我经常在executioncalar cmd上得到这个错误。你可以帮我解决..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆