can't filling text boxes from MySql query using

Hi guys,

A have a form with some text boxes that I need to fill from a MySql query, the problem is that only the first text box is filled and the rest remains empty, I hope you guys can help me please.

    Private Sub lstNombres_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstNombres.SelectedIndexChanged
            Dim cRegistro As String = lstNombres.SelectedItem
            Dim cClave As String = Trim(Microsoft.VisualBasic.Right(cRegistro, 5))
            Dim nClave As Integer = CInt(cClave)
            Dim cQuery As String

            If Conn.State = ConnectionState.Closed Then
            End If

            cQuery = "SELECT * FROM registros where registros.clave =  '" & nClave & "'"

            Command = New MySqlCommand(cQuery, Conn)
            Reader = Command.ExecuteReader()

            While Reader.Read()
                txtNumeroLan.Text = Reader.GetString("Lan")
                txtLanRecibido.Text = Reader.GetString("LanRecibido")
                txtNombre.Text = Reader.GetString("Nombre")
                txtPaterno.Text = Reader.GetString("Paterno")
                txtMaterno.Text = Reader.GetString("Materno")
                txtNumeroDocumento.Text = Reader.GetString("Numerodocumento")
                txtCiudadTramita.Text = Reader.GetString("Ciudadtramite")
                txtTelefonoCelular.Text = Reader.GetString("Telcelular")
                txtTelefonoOtro.Text = Reader.GetString("Telotro")
                txtObservaciones.Text = Reader.GetString("Observaciones")
            End While
        Catch ex As Exception
        End Try
    End Sub
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guru JiCommented:
In your while read,

Instead of Reader.GetString("Field Name")

try Reader.GetString(0), Reader.GetString(1), Reader.GetString(2)

0,1,2 are based on the fileds you have in the select statement.
0 is for Lan field
1 is for LanRecibido ... and so on.

Try this and report if that fixes anything because sometimes if field names are not exact or have any space it won't display correct where as specifying the number for that field will display the content regardless of the name.
elm9999Author Commented:
No, it doesn't wotk :(

            While Reader.Read()
                txtNumeroLan.Text = Reader.GetString(1)
                txtLanRecibido.Text = Reader.GetString(2)
                txtNombre.Text = Reader.GetString(3)
                txtPaterno.Text = Reader.GetString(4)
                txtMaterno.Text = Reader.GetString(5)
                txtNumeroDocumento.Text = Reader.GetString(8)
                txtCiudadTramita.Text = Reader.GetString(12)
                txtTelefonoCelular.Text = Reader.GetString(13)
                txtTelefonoOtro.Text = Reader.GetString(14)
                txtObservaciones.Text = Reader.GetString(15)
            End While

On the output debug of the coding windows apears this:

A first chance exception of type 'System.Data.SqlTypes.SqlNullValueException' occurred in MySql.Data.dll
Data is Null. This method or property cannot be called on Null values.
Guru JiCommented:
You need to check for IsDBNull:

  txtNumeroLan.Text = Reader.GetString(1);
That's your only reliable way to detect and handle this situation and you have to do it for each text box.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

elm9999Author Commented:
Great Guru !!!

it's done and working good. I only change your last example  you made for PHP :)

If Not (Reader.IsDBNull(1)) Then
      txtNumeroLan.Text = Reader.GetString(1)
End If
elm9999Author Commented:
Great Job!!!

Thank you
Guru JiCommented:
Thank you,

Sorry was working on php code that's where I wrote it. Great it worked for you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.