JAM Posted March 10, 2003 Posted March 10, 2003 Hi all I'm trying to fill the ListBox with selected student's name. Instead I have the ListBox fill with System.Data.DataRawView Here is my 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 Quote
Moderators Robby Posted March 10, 2003 Moderators Posted March 10, 2003 You can add a Where clause to you sql... "Select * from Student Where Student = 'Smith'" Quote Visit...Bassic Software
Cassio Posted March 10, 2003 Posted March 10, 2003 What do you mean by 'I have the ListBox fill with System.Data.DataRawView' ? Your code worked fine here. But I´m using SQL Server. Quote Stream of Consciousness (My blog)
JAM Posted March 10, 2003 Author Posted March 10, 2003 (edited) Dear Robby and Casio I added where clause but instead of showing Smith in my list box, it is showing System.Data.DataRawView Edited March 10, 2003 by JAM Quote
Cassio Posted March 10, 2003 Posted March 10, 2003 Maybe theres something wrong with your database, cause your code seems right. Try to use a datareader to fill your listbox. Quote Stream of Consciousness (My blog)
Cassio Posted March 11, 2003 Posted March 11, 2003 Did you try the datareader? Quote Stream of Consciousness (My blog)
JAM Posted March 11, 2003 Author Posted March 11, 2003 Thank you all I have it fixed. I had to add this line Dim Studentname as datacolumn = Student.columns.Add("Studentname") Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.