fniles,
As the other suggest I normally use dr.IsDBNull(0) also.
However the "problem" you are having is that dr.GetString is attempting to
return a String, when you have a Null. You then attempt to pass this String
to the IsDBNull function. You need to pass an Object to the IsDBNull
function, you can use need to use dr.GetValue to retrieve this object then
use the IsDBNull function:
If IsDBNull(dr.Get Value(0)) Then
However as I stated, I simply use dr.IsDBNull instead...
| If dr.IsDBNull(0) Then sUnable = "" Else sUnable =
| dr.GetString(0)
As it avoids "getting" the value twice...
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"fniles" <fn****@pfmail. com> wrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
|I am accessing MS Access db with tblA whose column UNABLE can have NULL
| value. When I access UNABLE whose value is null, I got an error "
| Run-time exception thrown : System.InvalidC astException - Specified cast
is
| not valid." either when I do
| IsDBNull(dr.Get String(0))
| or
| dr.GetString(0)
| How can I fix this problem ?
|
| Thanks.
|
| Dim sUnable as string
| Dim sql As String
| Dim dr As OleDb.OleDbData Reader
| Dim cmd As New OleDb.OleDbComm and
|
| sql = "select UNABLE from tblA where ACCOUNT = 'xyz'"
| With cmd
| .Connection = g_ConnectionDem oOLE
| .CommandText = sql
| dr = .ExecuteReader( )
| End With
| Do While dr.Read
| If bErr Then
| sUnable = ""
| Else
| If IsDBNull(dr.Get String(0)) Then sUnable = "" Else sUnable =
| dr.GetString(0) --> ERROR HERE
| End If
| If bErr Then sUnable = ""
| Loop
|
|
|
|