Home > Blockchain >  "System.Windows.Forms.PlaceholderTextBox, Text: " Error when inserting data in MySQL datab
"System.Windows.Forms.PlaceholderTextBox, Text: " Error when inserting data in MySQL datab

Time:10-29

Am trying to capture data from textbox to save it to mysql database but the field is System.Windows.Forms.PlaceholderTextBox, Text: Adm

This is my Buttonsave click event save

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

This is what am getting at the moment

enter image description here

anyone with an idea how to go about this?

Faithfully Moe

CodePudding user response:

You had the answer yourself, in the first few lines of your code.

Where you set the values in the parameters, none of the lines are using the value, they are getting the object.

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

Change to:

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

Each of the lines has a .Text at the end to extract the value of the object.

  • Related