Solved

How to correctly reference a reader element ?

Posted on 2009-07-05
4
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 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