Click here to Skip to main content
15,664,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

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;

Can anyone help me?

1 solution

That is because you have used a fixed length data type.

change the data type to a variable length type.[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900