SelectedValue coming up blank in listbox

VonEhle

Active member
Joined
Feb 20, 2006
Messages
26
Programming Experience
Beginner
When I run my program, it fills up the listbox properly, but when I try getting the SelectedValue, it comes back empty. I tested it by having a msgbox pop up with just the SelectedValue. Can someone tell me why the value wouldn't work?


VB.NET:
Public Class frmCourseList

    Public strStudents As String
    Public sqlconn As New SqlConnection("Data Source = .\SQLExpress; Initial Catalog = STATEUBOOKSTORE; Integrated Security = True")

    Private Sub frmCourseList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Open the connection 
        sqlconn.Open()

        'Declare a command and assign a SQL string to it
        Dim sqlcomm As SqlCommand = sqlconn.CreateCommand()
        sqlcomm.CommandText = "SELECT * FROM Students"

        'Declare a datareader 
        Dim drd1 As SqlDataReader = sqlcomm.ExecuteReader()

        While drd1.Read()
            lstStudents.Items.Add(drd1(1).ToString & " " & drd1(2).ToString)

        End While
       
        'drd1.Close()
    End Sub
 
Back
Top