When I was making something today, I discovered a very strange problem. The field setting type in the database (SqlServer) is ntext, but the saved data is always very short. I initially thought that a length limit was set in a certain section of the program. After setting After breakpoint tracking and debugging, I found that the transmitted data is normal, but after performing the storage operation, the saved content is always very short. The number of characters saved is 16, and the length of the field type ntext set in the database is also It was 16, so I thought it was a bug in the database, so I wrote an insert statement in the query analyzer to test it. It turned out that the saved content was normal, so the problem must be in the program. Finally, I found that the parameter object SqlParameter was constructing the SqlCommand command object. The specified parameter type is ntext and its length is specified as 16. The writing method is as follows
SqlParameter[] parms = new SqlParameter[] {
new SqlParameter(TEMPLATEID, SqlDbType.Int),
new SqlParameter("@Content", SqlDbType.NText,16)
};
Remove the length limit and test again. Everything is OK. Haha, it seems that the concepts of many things are not very clear and can easily cause trouble. I hope this lesson can give some tips to my friends who encounter similar problems in the future. .