此vb净代码未连接到mysql

时间:2019-12-23 10:13:19

标签: mysql vb.net

我已经在VB.Net中编写了此代码。

Public Class DBConf
    Public connectionstring As String
    Public mysqlconnection As New MySqlConnection(connectionstring)

Private Sub ButtonConnect_Click(sender As Object, e As EventArgs) Handles ButtonConnect.Click

        connectionstring = "datasource=" & TextBox1.Text & ";port=" & TextBox2.Text & ";username=" & TextBox3.Text & ";password=" & TextBox4.Text


        Try

            mysqlconnection.Open()
            MsgBox("Connesso!", MessageBoxIcon.Information)

        Catch ex As Exception
            MsgBox(ex.ToString)
            'MsgBox("Connessione non riuscita. Verificare i dati immessi e riprovare.", MessageBoxIcon.Error)

        End Try

其中的文本框表示用户输入。 它没有连接到我的MySQL Server。 但是,如果我将我的字符串而不是变量{connectionstring“放在Public mysqlconnection As New MySqlConnection(connectionstring)中,它将连接。 怎么了 谢谢大家。

0 个答案:

没有答案