Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataReader in VB.NET problem reading null fields from Oracle 1

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
US
Hello there...

I have an ODBC DataReader connected to an Oracle DB. It seems to work all right most of the time, but in one case I need to read data from a table that has null values in a Date field. When the DataReader hits that, I'm getting a conversion error saying conversion from type DBNull to type 'Date' is not valid.

The SQL string I'm using to get the data is quite simple, "SELECT * FROM USERS". Is there some way I can structure this to ignore the nulls, or present them some other way (such as empty strings, or a literal I can read and work around?

Thanks for any help you can offer.


CraigHartz
 
Certainly...You can use Oracle's NVL function, which works in this fashion:
Code:
SELECT NVL(<expression>,<replacement>)
  FROM <some table>...
The above code means, "If <expression> evaluates to NULL, then produce <replacement> as the output of the function; If <expression> does not evaluate to NULL, then the function returns <expression>.

Let us know if this is helpful.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Thanks SM, that worked. Unfortunately (fortunately?) it looks like I have other issues with the Datareader object that are handled correctly by using a dataset / datatable instead, so I've abandoned that line of thinking. But I really appreciate the help!




CraigHartz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top