Determine the data type of a column

  • Thread starter Thread starter Bob Day
  • Start date Start date
B

Bob Day

VS 2003, sql

How do you determine the data type of a column if its value is DBNull?

1)Table:
Column1 STRING non-nullable

2) Fill to a DataSet via DataAdapter

3) dim Data_Type_Is as object
Data_Type_Is = DataSet.DataTable(row1).column1??????????

I don't see how to get the data type. Things like gettype will give you the
type of the value, which would be DBNull if that is the value. I want to
get "STRING" back.

Please advise.

Bob Day
 
No, you have got the question backwards.
The table already exists. I want to know the Data Type of the column, not
of the value in the column.
In other works, if the value in the column is <NULL>, then
column1.gettype.name produces "DBNull" even if it is defined as a STRING.
If the value is a string, then it does produce STRING.

Please advise.

Bob Day
 
Bob:

I know the table exists, so do the columns and rows. What's happening is
that you are checking the value you are checking against is the problem.
Both a given value and the Column as a whole have a Type. Did you check on
the link I posted? Look at this
then...http://www.informit.com/isapi/product_id~{46BDD2C1-0C2B-4BC0-B701-3
AEF1FD50913%7D/content/index.asp

Try this, Set the value to a string manually where you get DBNull right now.
It will change. It won't be dbnull anymore. That changes from Row to row.
The type of the value is different from the DBType of the column.

http://www.devarticles.com/art/1/118/4

HTH,,

Bill
 
Back
Top