Answered by:
why can not update string type with length 256?

Question
-
Error is String or binary data would be truncated.
The statement has been terminated.Why can not update string type with length 256?
CryptographyManager defaultCrypto = EnterpriseLibraryContainer.Current.GetInstance<CryptographyManager>(); PasswordObject pwd = new PasswordObject(New_Password.Text.Trim().ToUpper()); byte[] serializedObject = SerializationUtility.ToBytes(pwd); byte[] encrypted = defaultCrypto.EncryptSymmetric("RijndaelManaged", serializedObject); string updateString = "Update UserProfile set Password = '" + Convert.ToBase64String(encrypted) + "', Last_PasswordChange_Date = '" + DateTime.Now.ToString("yyyy-MM-dd 00:00:00") + "' where upper(rtrim(UserID)) = upper(rtrim('" + UserID + "'))";
string error_test = Util.ExecuteDatabase(updateString);
Hello
Answers
-
Most probably the type of the column in the database is varchar(255) so it simply cannot hold 256 characters.
You are aware of the fact that the way you wrote the statement it's 1) susceptible to SQL injection attacks and 2) not going to use any index even if you happened to have one on the UserProfile table?
----------------------------------
http://jendaperl.blogspot.com
A Perl developer in the world of C#- Marked as answer by 沈世鈞 Tuesday, June 28, 2011 1:11 AM
All replies
-
Most probably the type of the column in the database is varchar(255) so it simply cannot hold 256 characters.
You are aware of the fact that the way you wrote the statement it's 1) susceptible to SQL injection attacks and 2) not going to use any index even if you happened to have one on the UserProfile table?
----------------------------------
http://jendaperl.blogspot.com
A Perl developer in the world of C#- Marked as answer by 沈世鈞 Tuesday, June 28, 2011 1:11 AM
-
-
Set where? In the database? Really? Script out the table and show us the sql!
If the database column really is nvarchar(max) and you are really accessing the database you think you are accessing then there must be a trigger on that table trying to copy the value into some other table that still has nvarchar(255).
----------------------------------
http://jendaperl.blogspot.com
A Perl developer in the world of C# -