Setting column Width of new column

S

Sid Price

I have an application that needs to add a column to one of its database
tables. I am doing this with the "ALTER TABLE" command and setting the new
column to have a width of 80. The query looks like this:

DBCommand.CommandText = "ALTER TABLE " & strTableName & " ADD "
& strColumnName & " char(" & iColumnSize & ")"
DBCommand.ExecuteNonQuery()

Later the new column in the table may have data assigned into the new
column. When this is done the data entered into the column is always 80
chars long regardless of the actual string length. This is not the behavior
we see if we add the column in Access and enter text in the new field. I
have examined the table design in Access and do not see any difference
between this column and other text columns except for the length (80 instead
of 50 in other columns).

Is there some attribute that needs to be set on the new column so that the
entry is not space-filled to the maximum column size?

Thanks,
Sid.
 
G

Guest

Sid,

If this is an Access database then I think you need to use the "Text" data
type, not the "Char" data type to get a variable length column with a maximum
size.

If this is SQL Server then I think you need one of the "VARCHAR" data types.

Kerry Moorman
 
S

Sid Price

Kerry,

Thank you that fixed my problem,
Sid.

Kerry Moorman said:
Sid,

If this is an Access database then I think you need to use the "Text" data
type, not the "Char" data type to get a variable length column with a
maximum
size.

If this is SQL Server then I think you need one of the "VARCHAR" data
types.

Kerry Moorman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top