views:

41

answers:

2

Hi, I'm working with VS2010 and asp.net and build a SQL Server Database with some int and char values.

My problem is, that the char(50) automatically fills the unused chars with whitespaces like:

"foo           " 

What can i do to get only "foo"?

+7  A: 

Change it to varchar(50). The char(50) data type will fill the remaining characters of the field with spaces.

+2  A: 

It's not Visual Studio that's adding the white spaces, but your datatype.

Char is fixed-length, while varchar is variable length. Char will pad the remaining text with spaces up to your field length.

You can see more information about SQL datatypes here.

LittleBobbyTables