【问题标题】:How to get all names of the column in MySql database to display in comboBox如何获取 MySql 数据库中列的所有名称以显示在组合框中
【发布时间】:2015-01-07 16:33:28
【问题描述】:

我有一个表单,我喜欢检索 MySql 数据库中的所有列,并使用 vbNET 中的组合框显示它。 我不知道如何查询。 这是我的示例代码:

conn = 新的 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

【问题讨论】:

  • @StuartSiegler,我替换了我的 MySqlCommand 像这样“select * from information_schema.columns where table_schema = 'dbase' and table_name = 'tblgrade_section'”,但它没有在组合框中显示任何内容。
  • 我想我误解了这个问题(以为是“什么是查询”)

标签: mysql vb.net combobox


【解决方案1】:

我希望重新提出问题,因为建议的重复链接正确时参考 VB.NET 标记是不完整的。 您还可以使用连接的GetSchema 方法提取有关表列的信息....

例如

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

您可以在SqlConnection页面了解GetSchema looking at the MSDN docs的内部工作原理。我不知道 MySql 连接器是否支持所有选项或更多,但这可能是其他搜索的起点

【讨论】:

  • 我想我误解了这个问题(以为是“查询是什么”)
猜你喜欢
  • 2016-08-08
  • 2018-08-17
  • 2012-12-27
  • 1970-01-01
  • 1970-01-01
  • 2021-05-27
  • 2011-09-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多