我正在尝试使用下面的可视化基本代码将用户数据插入mysql数据库,但我只是收到我的MessageBox,说“注册成功!”并且没有对用户数据库表进行任何更改 注意:我已经导入MySql.Data.MySqlClient并启动了Conn,Cmd,Cmd1和Rdr
Private Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
Conn = New MySqlConnection
Conn.ConnectionString = "server=localhost;userid=root;password=mmmsss123;database=gymdb"
txtUName.Text = txtUName.Text.ToLower()
txtUName.Text = txtUName.Text.Replace(" ", "")
txtPassword.Text = txtPassword.Text.ToLower()
txtPassword.Text = txtPassword.Text.Replace(" ", "")
Try
Conn.Open()
Dim Query As String
Query = "select * from gymdb.user where username='" & txtUName.Text & "'"
Cmd = New MySqlCommand(Query, Conn)
Cmd.ExecuteNonQuery()
Rdr = Cmd.ExecuteReader
Dim Count As Integer = 0
While Rdr.Read
Count += 1
End While
Rdr.Close()
Conn.Close()
If Count >= 1 Then
MessageBox.Show("This Username Is Already Registered!" & Environment.NewLine & "Please Enter Another Username", "Registeration State")
Else
If txtUName.Text <> "" And txtPassword.Text <> "" Then
Conn.Open()
Query = "insert into gymdb.user (username, upassword) values ('" & txtUName.Text & "', '" & txtPassword.Text & "')"
Cmd1 = New MySqlCommand(Query, Conn)
MessageBox.Show("Registered Successfully!", "Registeration State")
Conn.Close()
Else
MessageBox.Show("Not Valid Username Or Password!" & Environment.NewLine & "Please Enter Valid Username And Password", "Registeration State")
End If
End If
Catch ex As MySqlException
MessageBox.Show(ex.Message, "Error!")
Finally
Conn.Dispose()
End Try
End Sub
答案 0 :(得分:0)
答案是: 丢失
Cmd1.ExecuteNonQuery()