Solved

How to correctly reference a reader element ?

Posted on 2009-07-05
4
157 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Get String split 5 33
Create XML 5 34
Copy/Clone an object. 9 18
Datagridview control last row back color red vb.net 4 23
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now