为什么插入SQL数据库时,我的字符串值累计空的空间? [英] Why is my string value accumulating empty spaces when inserting into SQL database?

查看:132
本文介绍了为什么插入SQL数据库时,我的字符串值累计空的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个广泛的形式插入到SQL数据库,然后从管理页面,我要求所有的数据并将其插回到管理页面的表单。在原来插入到数据库中,这个特定的dropdownlist(只是他人等)被插入所选择的数据。但是,当我去到数据库中,眼前这个特定的细胞越来越3〜4个空空格选定值插入后。这导致了布尔比较试图插入回管理员的表单时以虚假的回应。即(主==主)= FALSE。因此将DropDownList不会被更新。

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.

什么是导致SQL行添加这些空出的空间?在code是其code后面的所有HTML dropdownlists相同。和SQL数据库的结构似乎相同通过以及一路

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。要撤销我试图在code使用.Trim()背后的问题。但这不是作出区别。看来SQL数据库将在插入空白。

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.

推荐答案

请问你的专栏,多数民众赞成加入的空白正好是一个 CHAR NCHAR 而不是 VARCHAR NVARCHAR ?例如,如果你列的数据类型为 CHAR(10),并插入一个喂了进去,总是会有在列,因此5空白字符将被添加10个字符之后,你好。但是,如果你使用 VARCHAR(10),这将不会发生。

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.

这篇关于为什么插入SQL数据库时,我的字符串值累计空的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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