Search code examples
c#databasemdf

how delete spaces in a data (database) after a word


I have a problem.. When I recup the information in my database, I have a lot of blanks after my word because the size in the cells is 10 and I have a word with a size of 3 (example: "abc" and I recup the world "abc ").

Thanks !


Solution

  • The problem is that you are saving text data in fix length data types like char. Try to use a variable length datatype like nvarchar. You can also use trim functions to remove spaces in the select like

    select LTRIM(RTRIM(myColumn)) from myTable
    

    You can also remove the spaces after the database layer, with c# String.Trim function like this: "my string ".Trim();