|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Setting column Width of new columntables. 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. 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 Show quote "Sid Price" wrote: > 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. > > > Kerry,
Thank you that fixed my problem, Sid. Show quote "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message news:E17EA33A-9FD0-4340-AE90-7680C6DDA67D@microsoft.com... > 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 > > > "Sid Price" wrote: > >> 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. >> >> >> |
|||||||||||||||||||||||