摆脱SQL字符串中不必要的空格 [英] Get rid of unwanted white space in SQL strings

查看:74
本文介绍了摆脱SQL字符串中不必要的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用Linq to SQL在C#中编写程序.
问题是当我定义一个列时,例如:
列:密码
类型:字符串(长度= 20)


当我保存一个小于最大长度的字符串时,剩余的值将由空白填充.例如:

Hi,
I am writing a program in C# using Linq to SQL.
the problem is that when I define a column for example:
Column: Password
Type: String(length=20)


And when my save a string that has less than the maximum length, the remained value is filled by white space. For example:

Value="myPassword          "



但是我正在寻找的东西具有这样的价值:



But the thing I am looking for is having such a value:

Value="myPassword"



我以这种方式加载程序,由于存在问题,我不喜欢使用String.Trim函数:



I load my program in a way like this, and I do not like to use String.Trim function because of its problems:

[Table(Name = "Users")]
public class UserLoginData
{
    [Column(Name = "Enable")]
    public bool Enable = false;
    [Column(Name = "UserName")]
    public string UserName = "";
    [Column(Name = "Password")]
    public string Password = "";
    [Column(Name = "Server")]
    public string Server = "";
    [Column(Name = "Proxy")]
    public string Proxy = "";
    [Column(Name = "ProxyUserName")]
    public string Proxy_UserName = "";
    [Column(Name = "ProxyPassword")]
    public string Proxy_Password = "";
    [Column(Name = "Comment")]
    public string Comment = "";
    [Column(Name = "DataPath")]
    public string DataPath = "";
    [Column(Name = "LogoffTime_sec")]
    public int LogoffTime_sec = 0;
    [Column(Name = "LogoffTime_sec_sigma")]
    public int LogoffTime_sec_sigma = 0;
}
.
.
.
db = new DataContext(Users_DatabaseFileName);
Table<UserLoginData> UserserTable = db.GetTable<UserLoginData>();
users = from c in UserserTable
        select c;



谁能帮我吗?
:confused:
thx



Can anyone help me?
:confused:
thx

推荐答案

这是因为您使用了固定长度的数据类型.
将数据类型更改为可变长度类型.

http://msdn.microsoft.com/en-us/library/ms187752.aspx [ ^ ]
That is because you have used a fixed length data type.

change the data type to a variable length type.

http://msdn.microsoft.com/en-us/library/ms187752.aspx[^]


这篇关于摆脱SQL字符串中不必要的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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