Solved

How to correctly reference a reader element ?

Posted on 2009-07-05
4
162 Views
Last Modified: 2013-11-07
HI

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)
                    Else
                        'Si es Cliente Externo
                        tipocliente = String.Empty
                        nombrecliente = CType(reader("NOMBRE"), String)
                    End If

Open in new window

0
Comment
Question by:dimensionav
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 400 total points
ID: 24780964
because reader.IsDBNull() takes int as an parameter and you are trying to pass string.
0
 

Author Comment

by:dimensionav
ID: 24780978
is any other way to pass the element name ? the idea is just to make my code a little more clear.
Thanks
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 100 total points
ID: 24781752
you can do something like this:

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

if tipoclient is Nothing then
else
end if
0
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 400 total points
ID: 24781921
Try this:
If Not String.IsNullOrEmpty(reader("ID_EMPLEADO_FARRERA").ToString()) Then
    // your code goes here
End If
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question