Is there a way to programmatically determine if a SQL Server field is
of type CHAR vs. VARCHAR?

I'm able to use the DataColumn.DataType property to determine that a
field is a string, and to retrieve its max length. As far as I can
tell, however, both CHAR and VARCHAR fields look the same when using
the DataColumn object.

This for a stored procedure code generator that is complete except for
this one feature.

TIA
Jared

Re: Determining field type CHAR vs VARCHAR by Marina

Marina
Thu Jul 13 15:27:32 CDT 2006

You can query the sql server system tables to find out. Try looking at
syscolumns.

"Jared" <google@tripletreesoftware.com> wrote in message
news:1152821579.889154.28430@p79g2000cwp.googlegroups.com...
> Is there a way to programmatically determine if a SQL Server field is
> of type CHAR vs. VARCHAR?
>
> I'm able to use the DataColumn.DataType property to determine that a
> field is a string, and to retrieve its max length. As far as I can
> tell, however, both CHAR and VARCHAR fields look the same when using
> the DataColumn object.
>
> This for a stored procedure code generator that is complete except for
> this one feature.
>
> TIA
> Jared
>



Re: Determining field type CHAR vs VARCHAR by Jared

Jared
Thu Jul 13 17:34:57 CDT 2006

Hi Marina,

I was hoping this would be exposed in DataColumn, but querying the
system tables should work, too. Thanks for your quick response!

Jared

Marina Levit [MVP] wrote:
> You can query the sql server system tables to find out. Try looking at
> syscolumns.
>


Re: Determining field type CHAR vs VARCHAR by Mark

Mark
Fri Jul 14 14:30:39 CDT 2006

Bear in mind that the DataSet and the actual table within SQL are very
different things - a DataTable is not an SQL table, it just so happens that
you can fill a DataTable from an SQL table - therefore the DataTable column
types aren't the same as the SQL column types and the DataTable attributes
don't neccessarily represent the associated SQL table.

You'll see the same problem with default values in SQL tables - they aren't
represented in the associated DataTable at all.

--
Best regards
Mark Baldwin

"Jared" <google@tripletreesoftware.com> wrote in message
news:1152830097.676054.120200@p79g2000cwp.googlegroups.com...
> Hi Marina,
>
> I was hoping this would be exposed in DataColumn, but querying the
> system tables should work, too. Thanks for your quick response!
>
> Jared
>
> Marina Levit [MVP] wrote:
>> You can query the sql server system tables to find out. Try looking at
>> syscolumns.
>>
>