ListBox is NOT displaying what I want

JAM

Member
Joined
Mar 9, 2003
Messages
24
Hi all
Im trying to fill the ListBox with selected students name. Instead I have the ListBox fill with System.Data.DataRawView

Here is my code:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim thedata As DataSet
        Dim theAdapter As OleDb.OleDbDataAdapter
        Dim connectstring, sqlstr As String
        connectstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\student.mdb"
 
       sqlstr = "Select * from Student"
        thedata = New DataSet()

        Dim Student As DataTable = thedata.Tables.Add("Student")

        theAdapter = New OleDb.OleDbDataAdapter(sqlstr, connectstring)
        theAdapter.Fill(thedata, "Student")
        ListBox1.DataSource = thedata.Tables("Student")
        ListBox1.DisplayMember = "Studentname"
 End Sub
 
Dear Robby and Casio
I added where clause but instead of showing Smith in my list box, it is showing System.Data.DataRawView
 
Last edited by a moderator:
Maybe theres something wrong with your database, cause your code seems right.
Try to use a datareader to fill your listbox.
 
Thank you all
I have it fixed. I had to add this line

Dim Studentname as datacolumn = Student.columns.Add("Studentname")
 
Back
Top