Determining field type CHAR vs VARCHAR

  • Thread starter Thread starter Jared
  • Start date Start date
J

Jared

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
 
You can query the sql server system tables to find out. Try looking at
syscolumns.
 
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
 
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.
 
Back
Top