我正在嘗試從文本框中捕獲資料以將其保存到 mysql 資料庫,但該欄位是System.Windows.Forms.PlaceholderTextBox, Text: Adm
這是我的 Buttonsave 點擊事件保存
Dim theFirstname As String = firstName.Text
type here
Dim theEmail As String = emailCom.Text
Dim username As String = userName2.Text
Dim thePassword As String = passWord2.Text
If theFirstname.Trim() = "" Or theEmail.Trim() = "" Or username.Trim() = "" Or thePassword.Trim() = "" Then
MessageBox.Show("One Or More Fields Are Empty", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Stop)
ElseIf Usernamexist(username) Then
MessageBox.Show("This Username Already Exists, Choose Another One", "Duplicate Username", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
connection.Open()
Dim command As New MySqlCommand("INSERT INTO authentic (firstname, email, username, password) VALUES (@firstname,@email,@username,@password)", connection)
command.Parameters.Add("@firstname", MySqlDbType.VarChar).Value = firstName
command.Parameters.Add("@email", MySqlDbType.VarChar).Value = emailCom
command.Parameters.Add("@username", MySqlDbType.VarChar).Value = userName2
command.Parameters.Add("@password", MySqlDbType.VarChar).Value = passWord2
connection.Open()
MessageBox.Show("Registration Completed Successfully", "User Added", MessageBoxButtons.OK, MessageBoxIcon.Information)
connection.Close()
If command.ExecuteNonQuery() = 1 Then
MessageBox.Show("Registration Completed Successfully", "User Added", MessageBoxButtons.OK, MessageBoxIcon.Information)
connection.Close()
Else
MessageBox.Show("Something Happen", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
connection.Close()
End If
firstName.Text = ""
emailCom.Text = ""
userName2.Text = ""
passWord2.Text = ""
accLogin.Visible = True
createAcc.Visible = False
End If
這就是目前得到的

有人知道如何解決這個問題嗎?
忠實的萌
uj5u.com熱心網友回復:
在代碼的前幾行中,您自己就有了答案。
在引數中設定值的地方,沒有一行使用該值,它們正在獲取物件。
command.Parameters.Add("@firstname", MySqlDbType.VarChar).Value = firstName command.Parameters.Add("@email", MySqlDbType.VarChar).Value = emailCom command.Parameters.Add("@username", MySqlDbType .VarChar).Value = userName2 command.Parameters.Add("@password", MySqlDbType.VarChar).Value = passWord2
改成:
command.Parameters.Add("@firstname", MySqlDbType.VarChar).Value = firstName.Text
command.Parameters.Add("@email", MySqlDbType.VarChar).Value = emailCom.Text
command.Parameters.Add("@username", MySqlDbType.VarChar).Value = userName2.Text
command.Parameters.Add("@password", MySqlDbType.VarChar).Value = passWord2.Text
每行末尾都有一個.Text以提取物件的值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/525270.html
