Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why blank spaces are entered into DB

Status
Not open for further replies.

organicg

Programmer
Oct 21, 2002
151
US
I have a form with a phone# field that populates the @Phone param of an .NET SQLCommand object used to do an Insert into a table. The DB field is char(12), as is the param. The field is not required. I populate the param with:
SqlCommandINSERT.Parameters("@Phone").Value = trim(Phone.Text)
After this statement executes, I confirm that the param value is "", not " ". However, when I look in the DB, the phone field appears to have 12 blank spaces, but why? It should be an empty string.
This DB field allows nulls, though I always enter a string, even a blank, and probably should change it to not allow nulls.
 
because your field has type CHAR(12)
you shoulD use type VARCHAR(12)
 
kolt's right. as an explanation, char(12) will hold a fixed string of 12 characters. therefore you will always have 12 chars, even if the field is emtpy. varchar means it is variable, so when there are no values, it will be empty, but will fill characters as needed up to 12 chars in that column.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top