1

I Have a form and I like to retrieve all the columns in MySql database and display it using comboBox in vbNET. I dont know how to query that. Heres my sample codes:

conn = New MySqlConnection conn.ConnectionString = "server=localhost; userid=root; password=root; database=dbase"

    Dim da As New MySqlDataAdapter
    Dim dt As New DataTable
    Dim bs As New BindingSource
    Dim ds As New DataSet
    Try
        ds.Clear()
        conn.Open()
        cmd = New MySqlCommand("[watt??]")
        da = New MySqlDataAdapter(cmd)
        da.SelectCommand.Connection = conn
        da.Fill(ds, "gradelvl")
        cbGradeLvl.Text = ds.Tables(0).Rows(0).Item(0)

    Catch ex As MySqlException
        MsgBox(ex.Message)
    Finally
        conn.Close()
    End Try
Philip Olson
  • 4,662
  • 1
  • 24
  • 20
Fvcundo
  • 95
  • 2
  • 3
  • 11
  • 1
    Possible duplicate of http://stackoverflow.com/questions/5648420/get-all-columns-from-all-mysql-tables – Stuart Siegler Jan 07 '15 at 16:35
  • @StuartSiegler, I replaced my MySqlCommand like this "select * from information_schema.columns where table_schema = 'dbase' and table_name = 'tblgrade_section'" but it doesnt display anything in the combobox. – Fvcundo Jan 07 '15 at 17:00
  • 1
    I guess I misunderstood the question (thought it was "what was the query") – Stuart Siegler Jan 07 '15 at 17:31

1 Answers1

1

I wish to reopen the question because the suggested duplicate link while correct is incomplete in reference to the VB.NET tag. You could extract informations about your table columns also using the GetSchema method of your connection....

For example

Using cnn = new MySqlConnection(.....)
    cnn.Open()
    Dim dt = cnn.GetSchema("Columns", new string () {Nothing, Nothing, "gradelvl"})
    for each row in dt.Rows
        cbGradeLvl.Items.Add(row("COLUMN_NAME").ToString)
    Next
End Using

You can get an understanding of the inner working of GetSchema looking at the MSDN docs on the SqlConnection page. I don't know if the MySql Connector supports all the options or more, but that could be a starting point for other searches

Steve
  • 213,761
  • 22
  • 232
  • 286