How to correctly reference a reader element ?


I have noticed that each time I use reader.IsDBNull("element_name") instead of reader.IsDBNull(10)  doesn´t work.

I got the error "input string not in correct format " with the attached code

Thanks in advace.
If Not reader.IsDBNull("ID_EMPLEADO_FARRERA") Then ' This line triggers the error
                        ' Si es Empleado Farrera
                        tipocliente = CType(reader("ID_EMPLEADO_FARRERA"), String)
                        nombrecliente = CType(reader("NOMBRE_FARRERA"), String)
                        'Si es Cliente Externo
                        tipocliente = String.Empty
                        nombrecliente = CType(reader("NOMBRE"), String)
                    End If

Open in new window

Who is Participating?
guru_samiConnect With a Mentor Commented:
because reader.IsDBNull() takes int as an parameter and you are trying to pass string.
dimensionavAuthor Commented:
is any other way to pass the element name ? the idea is just to make my code a little more clear.
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
you can do something like this:

tipocliente = Convert.ToString(reader("ID_EMPLEADO_FARRERA"))

if tipoclient is Nothing then
end if
guru_samiConnect With a Mentor Commented:
Try this:
If Not String.IsNullOrEmpty(reader("ID_EMPLEADO_FARRERA").ToString()) Then
    // your code goes here
End If
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.