我正在尝试学习使用带有 MYSQL 的 VB 程序进行注册。
我是新手,最近知道如何连接到 mysql 并注册。
现在的问题是......我修改了太多代码,我不能再注册了。
和
我想做以下事情:
1.只能注册一个唯一的用户名(输入相同的用户名显示错误)-------2. 用户名长度>5,密码长度>6-----3。显示注册完成
我只是……迷路了……需要很多帮助。谢谢你。
Private Sub btnReg_Click(sender As Object, e As EventArgs) Handles btnReg.Click
Dim myAdapter As New MySqlDataAdapter
Dim myCommand As New MySqlCommand
Dim myData As MySqlDataReader
Dim add As String
Dim connect As MySqlConnection
connect = New MySqlConnection()
connect.ConnectionString = "server=localhost;user id=jackie588727;password=jackie1218;database=root"
Dim usercheck As String = "SELECT Username FROM User WHERE Username = '" + txtUser.Text + "'"
Try
connect.Open()
Catch myerror As MySqlException
MsgBox("Error connecting to database. Check your internet connection.", MsgBoxStyle.Critical)
End Try
myCommand.Connection = connect
myCommand.CommandText = usercheck
myAdapter.SelectCommand = myCommand
myData = myCommand.ExecuteReader
If myData.HasRows = 0 Then
add = "INSERT INTO user (Username, Password) VALUES('" + txtUser.Text + "','" + txtPass.Text + "')"
Else
MsgBox(txtUser.Text & " is being register, try again.", MsgBoxStyle.Information)
End If
connect.Close()
End Sub