Error with DBNull

  • Thread starter Filipe Cristóvão
  • Start date
F

Filipe Cristóvão

Hi,
I know that this is a newbie's question, but I need to know how i do to know
if a field in a table is DBNull.
If I try to write (with response.write) the field, it gives me an error:
"Cast from type 'DBNull' to type 'String' is not valid".
Thanks for any help.
 
H

Hans Kesting

Filipe Cristóvão said:
Hi,
I know that this is a newbie's question, but I need to know how i do to know
if a field in a table is DBNull.
If I try to write (with response.write) the field, it gives me an error:
"Cast from type 'DBNull' to type 'String' is not valid".
Thanks for any help.

Various options:
* You can test against DBNull.Value (if (myDataRow["field"] == DBNull.Value) ... )
* DataRow has an IsNull(..) method to check a specific column in that row
* Don't cast to string, but use the ToString() method, DBNull gives an empty string

Hans Kesting
 
F

Filipe Cristóvão

Tks for the help.
I relly needed to know it.

--

Filipe Cristóvão

Hans Kesting said:
Hi,
I know that this is a newbie's question, but I need to know how i do to know
if a field in a table is DBNull.
If I try to write (with response.write) the field, it gives me an error:
"Cast from type 'DBNull' to type 'String' is not valid".
Thanks for any help.

Various options:
* You can test against DBNull.Value (if (myDataRow["field"] == DBNull.Value) ... )
* DataRow has an IsNull(..) method to check a specific column in that row
* Don't cast to string, but use the ToString() method, DBNull gives an empty string

Hans Kesting
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top