I have an extensive form inserting into a SQL database and then from an admin page I request all data and have it insert back into the form on the admin page. During the original insertion into the database, this specific dropdownlist (just like the others) is inserting the selected data. But when I go to the database, just this particular cell is getting 3 to 4 empty white spaces after the selected value is inserted. This is causing the boolean comparison to respond with false when attempting to insert back into the admin's form. i.e. ("Primary" == "Primary ") = false. So the dropdownlist is not updated.
What would be causing the SQL row to add these empty spaces? The code is identical for all the HTML dropdownlists with its code behind. And the structure of the SQL database seems identical all the way through as well.
p.s. To undo the problem I'm attempting to use .Trim() in the code behind. But this is not making a difference. It seems the SQL database adding the white space upon insertion.
SQL Server TRIM() Function The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string.
DML SQL query with space in a column name When we run INSERT, UPDATE, and DELETE statements, we must use a square bracket or double quotes to handle the column name with space.
White space is a character in a string that represents horizontal or vertical space in typography. In other words: tabs, line feeds, carriage returns and, yes, spaces. A white space has character value, just like 'A', 'B' and 'C' have a value.
Does your column thats adding whitespace happen to be a CHAR
or NCHAR
instead of VARCHAR
or NVARCHAR
? For example if your columns datatype is CHAR(10)
and you insert a "Hello" into it, there will always be 10 characters in that column so 5 whitespace characters will get added after "Hello". However, if you use VARCHAR(10)
, this won't happen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With