954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ListBox Showing Table Names

Hey all,

I'm trying to have a ListBox show a list of tables available in a database. This can then be selected to be used later on.

My problem is getting the actual table name to show up. I have the connection to the mysql database working properly, but it just shows "System.Data.DataRowView"

Here is the code I have so far:

Dim con As New MySqlConnection
Dim theQuery As New MySqlCommand
Dim theTables As New DataTable
Dim theAdapter As New MySqlDataAdapter
Dim strTable As String

strTable = "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'm_fyp2011_n0218430';"

con.ConnectionString = frmLogin.strconn

con.Open()
theQuery.Connection = con
theQuery.CommandText = strTable
theAdapter.SelectCommand = theQuery
theAdapter.Fill(theTables)
lstTables.DataSource = theTables
con.Close()


Thanks in advance for any help :)

Wolxhound90
Junior Poster in Training
55 posts since Mar 2011
Reputation Points: 10
Solved Threads: 1
 


Set the DisplayMember of the listbox to "TableName"

lstTables.DisplayMember = "Table_Name"

Add that after line 16 of your post.

When you don't set the display member it uses the ToString of the object. Thats why you see what you are seeing.

Unhnd_Exception
Posting Pro
570 posts since Nov 2010
Reputation Points: 249
Solved Threads: 201
 

Ah, I feel like such a noob sometimes lol.

This works perfect, thank you very much :)

Wolxhound90
Junior Poster in Training
55 posts since Mar 2011
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: