Start New Discussion within our Software Development Community

**THIS CODE RETRIEVES DATA FROM THE DATABASE. PLEASE HELP ME DEBUG. I AM EXPERIENCING ERROR CALLED INDEXOUTOFRANGE IN: **

HERE IS MY CODE:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



        'Try

        Dim oradb As String = "Provider=OraOLEDB.Oracle; Data Source=TRAVELMATE-PC/XE;User Id=cj;Password=me;"

        Dim conn As New OleDb.OleDbConnection(oradb)
        conn.Open()
        Dim cmd As New OleDb.OleDbCommand
        cmd.Connection = conn
        cmd.CommandText = "select last_name, first_name, middle_name from tenant where last_name = '" & Me.ComboBox1.Text & "' AND first_name = '" & Me.ComboBox2.Text & "' AND middle_name='" & Me.ComboBox3.Text & "'"
        cmd.CommandType = CommandType.Text
        Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader()
        If dr.Read() Then
            'Label5.Text = dr.Item("address")
            Label6.Text = dr.Item("contact_number")
        Else
            MessageBox.Show("Tenant does not exist!")
        End If

        dr.Dispose()
        cmd.Dispose()
        conn.Dispose()


       ' Catch ex As Exception
        ' MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
        ' Finally




    End Sub

Your select is

select last_name, first_name, middle_name

None of those items is the contact_number. Try changing your select to

select last_name, first_name, middle_name, contact_number
This article has been dead for over six months. Start a new discussion instead.