T
travlintom
Dim intCurID As Integer *** outside of code and available to all
***
Dim strConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Databases\ClientAppDB.mdb;"
Dim objConnection As New OleDbConnection(strConnectionString)
Dim strSQl As String = "SELECT CLIENTID, FIRSTNAME, LASTNAME
FROM CLIENTS ORDER BY LASTNAME"
Dim objCommand As New OleDbCommand(strSQl, objConnection)
Dim objDataReader As OleDbDataReader
Try
objConnection.Open()
objDataReader = objCommand.ExecuteReader *** is this
correct ***
While objDataReader.Read()
Me.ListBox1.Items().Add(objDataReader.Item(2) & ", "
& objDataReader.Item(1))
Me.ListBox1.ValueMember = objDataReader.Item(0)
End While
*** All this code works perfectly and the ValueMembers show as
correct when looping throught the data reader ***
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
intCurID = Me.ListBox1.SelectedValue
End Sub
*** Here I want get the current selected Value but ***
*** all it show is zero ***
*** Am I going about this the wrong way? I want to use ***
*** code and not the Properties on the form due to a ***
*** calculated SQL statment I use for the listbox ***
*** Thanks for any help ***
***
Dim strConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Databases\ClientAppDB.mdb;"
Dim objConnection As New OleDbConnection(strConnectionString)
Dim strSQl As String = "SELECT CLIENTID, FIRSTNAME, LASTNAME
FROM CLIENTS ORDER BY LASTNAME"
Dim objCommand As New OleDbCommand(strSQl, objConnection)
Dim objDataReader As OleDbDataReader
Try
objConnection.Open()
objDataReader = objCommand.ExecuteReader *** is this
correct ***
While objDataReader.Read()
Me.ListBox1.Items().Add(objDataReader.Item(2) & ", "
& objDataReader.Item(1))
Me.ListBox1.ValueMember = objDataReader.Item(0)
End While
*** All this code works perfectly and the ValueMembers show as
correct when looping throught the data reader ***
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
intCurID = Me.ListBox1.SelectedValue
End Sub
*** Here I want get the current selected Value but ***
*** all it show is zero ***
*** Am I going about this the wrong way? I want to use ***
*** code and not the Properties on the form due to a ***
*** calculated SQL statment I use for the listbox ***
*** Thanks for any help ***