如何从mysql中的单元格中选择并添加到button.text

时间:2016-08-24 05:39:58

标签: mysql visual-studio-2015

我是视觉工作室社区2015年visual basic的新手。

我在加载主要表单时尝试做什么

我有7个按钮需要更改文本字段以对应数据库中的条目。这些按钮可以由最终用户更改为现在的类别。 我在我的数据库中使用MySQL。任何帮助都会非常受欢迎,因为我搜索了谷歌和youtube,这是一个无尽的超载世界。

我的数据库结构如下,因为我无法嵌入图像: idbtncat btn_Name btn_caption PanelNo btn_image 1 btn_cat1 Pizza pnl_cat1 pizza.jpg

Public Class frm_MainConsole
Dim conn As New MySqlConnection

Sub dbconn()
    Dim DatabaseName As String = "posdb"
    Dim server As String = "localhost"
    Dim userName As String = "root"
    Dim password As String = "8943117"
    If Not conn Is Nothing Then conn.Close()
    conn.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, userName, password, DatabaseName)
    Try
        conn.Open()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

Private Sub frm_MainConsole_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.Show()
    dbconn()
    Dim query As String
    Dim command As MySqlCommand
    Dim reader As MySqlDataReader
    Try
        dbconn()
        query = "select * from posdb.button_cat where btn_caption"
        command = New MySqlCommand(query, conn)
        reader = command.ExecuteReader
        While reader.Read
            btn_Cat1.Text = reader("btn_caption")
            conn.Close()
        End While

    Catch ex As MySqlException
        MessageBox.Show(ex.Message)
    Finally
        conn.Dispose()
    End Try

End Sub

Private Sub testDatabaseConnectionToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles testDatabaseConnectionToolStripMenuItem.Click
    If mnit_dbConn.Text = "DB NOT Connected" Then
        dbconn()
        mnit_dbConn.Text = "DB CONNECTED"
    Else
        mnit_dbConn.Text = "DB NOT Connected"
        conn.Close()
    End If

End Sub

0 个答案:

没有答案