cool hit counter System.Data.SqlClient.SqlException: will truncate string or binary data_Intefrankly

System.Data.SqlClient.SqlException: will truncate string or binary data

Copyright: This is an original post by the blogger and may not be reproduced without the blogger's permission.


“System.Data.SqlClient.SqlException ”Unhandled exceptions of typeSystem.Data.dll occur in。 Additional information: Will truncate string or binary data

This is a problem encountered while doing this module on basic data setting for the server room charging system.

Originally, the UI layer of the code was used in the Try...... Catch caught the exception, as follows.

But for those who haven't encountered this problem, just reading this certainly won't solve it, so I put Try ...... Catch commented out and found the details of the thrown exception.


At first glance it was“System.Data.SqlClient.SqlException ”, Don't even think about it., It must be a database problem., After debugging, Discovery of field values inserted into the databasebasicDataBLL.SetDate the value of“2014/6/17 Tuesday”:

But the data type I set for this field in the database is varchar(10), which is far less than the space taken up by "Tuesday 2014/6/17"! So decisively increased the capacity of the data type by programming varchar(10) to varchar(20) and the problem was solved.

To sum up.

Some more testing, reducing the storable capacity of some other fields of type string, text, etc. in the database, also had this problem and came to a conclusion that

This problem arises because The data type of a field in the database is not sufficient to store the data length of the value to be inserted into the field , when the problem occurs, just increase the length of the corresponding field's data type appropriately.

1、How to calculate the value range of a data type in C
2、Are blockchain games really games Or is it just a speculative tool
3、Fundamentals From Template Syntax Data Binding Directives to Calculated Attributes Summary
4、Python bikesharing data analysis
5、How are transactions handled in JDBC

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送