I am using the code below. I have a list box in which there are some some names of people, on
selecting a name, the details pertaining on the selected name should be displayed in textboxes. I am using the following code but it does not work. What am I doing wrong or how do I use your code to make it run.
Private Sub lstEmployees_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEmployees.SelectedIndexChanged
Dim dbSource As String = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Payroll.mdb"
Dim db_command As New OleDbCommand, reader As OleDbDataReader
con.ConnectionString = dbSource
con.Open()
db_command.CommandText = "Select * from Employees where EmployeeNo = " & lstEmployees.SelectedIndex.ToString & ""
db_command.Connection = con
reader = db_command.ExecuteReader()
If (reader.read()) Then
TextBox1.Text = reader("FirstName").ToString
TextBox2.Text = reader("LastName").ToString
reader.close()
con.Close()
End If
End Sub