Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am developing a vb.net winform project that uses a sql server database to take in details of a person (e.g. name, contact number, address). I have set the length of each field in the database and on each textbox, e.g. email is set to 150 characters long. The problem is when I query the database to show a particular persons details, I noticed that there is a lot of white spaces at the end of each field coming back from the database e.g. if the email is 20 characters long there are 130 white spaces at the end of it. This is a problem because I have regex expressions to validate the email and contact number, that are returning false because of the white spaces at the end of each field. What can I do to solve this problem? Thanks in advance for your help.
Posted

1 solution

Try using VARCHAR rather than CHAR.

char and varchar (Transact-SQL)[^]

•Use char when the sizes of the column data entries are consistent.

•Use varchar when the sizes of the column data entries vary considerably.
 
Share this answer
 
v3
Comments
Member 10804519 13-Aug-14 4:39am    
Thanks a lot, that solved my problem.
PIEBALDconsult 13-Aug-14 10:31am    
Glad to be of service.

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