Hi, I want to ask about listbox things.
I made a Listbox, 3 textbox, and a Database
The Database Table is Member
The member field has 4 which is MemberID, Name, Address, Phone.
I have 2 records and it were display to the listbox which are Adry and Brandy (I get it from database name)
So, What I want is, when I click/select on Adry, the program will show Name, address , and phone to the 3 textboxes I made.
When I click/select on Brandy, the program will show the name, address, and phone to the 3 textboxes i made.
Anyway please take a look at my code :
This code is to get records from database and show it to the listbox
Sub loadlistbox() ListBox2.Items.Clear() Dim state = "SELECT * FROM Member ORDER BY Names" Dim Comm As OleDbCommand = New OleDbCommand(state conn) Try conn.Open() Dim reader As OleDbDataReader = sCommand.ExecuteReader() While reader.Read ListBox2.Items.Add(reader(1).ToString) End While sConnection.Close() Catch excep As System.Exception MsgBox(sException.Message, MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical) End Try If conn.State <> ConnectionState.Closed Then conn.Close() If ListBox2.Items.Count > 0 Then ListBox2.Items(0).Selected = True ListBox2.Focus() End Sub
And Here is my Code when the listbox select changed
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged Dim state= "SELECT * FROM Member ORDER BY Names" Dim commAs OleDbCommand = New OleDbCommand(state, conn) Try conn.Open() Dim readerAs OleDbDataReader = sCommand.ExecuteReader() While reader.Read TextBox1.Text = reader(1) TextBox2.Text = reader(2) TextBox3.Text = reader(3) End While Catch ex As Exception MsgBox("Error Loading Data", , "My Address Book") conn.Close() End Try 'btnDelete.Enabled = True End Sub
Something is wrong there, I don't now. It can show, but I can't click another record :(
I have done searching also from google but still I'm stuck. Please help.
Edited 7 Years Ago by Dorayaki: n/a