Solved

How to correctly reference a reader element ?

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

737 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