Determining field type CHAR vs VARCHAR

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
 
M

Marina Levit [MVP]

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

Jared

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
 
M

Mark

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.
 

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