If Me.textuser.Text = "" Then
MessageBox.Show("โปรดใส่ข้อมูล")
Exit Sub
End If
If Me.textpass.Text = "" Then
MessageBox.Show("โปรดใส่ข้อมูล")
Exit Sub
End If
Dim conn As MySqlConnection
conn = New MySqlConnection
conn.ConnectionString = "Server=localhost;User Id=root; Password=bossza; Database=bossza; Pooling=false"
Try
conn.Open()
Catch myerror As MySqlException
MsgBox("ไม่สามารถเชื่อต่อเซฟเวอร์ได้")
End Try
Dim myAdpter As New MySqlDataAdapter
Dim sqlquery = "SELECT * FROM member WHERE Username = ' " + textuser.Text + "'"
Dim myCommand As New MySqlCommand
myCommand.Connection = conn
myCommand.CommandText = sqlquery
myAdpter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()
If myData.HasRows = 0 Then
conn.Close()
conn.Open()
Dim registerfinal As New MySqlDataAdapter
sqlquery = "INSERT INTO member (Username,Password) VALUES ('" + textuser.Text + "','" + textpass.Text + "')"
myCommand.Connection = conn
myCommand.CommandText = sqlquery
registerfinal.SelectCommand = myCommand
myData = myCommand.ExecuteReader
MsgBox("สมัครสมาชิกเรียบร้อย")
textuser.Clear()
textpass.Clear()
Me.Hide()
Dim sqlquery = "SELECT * FROM member WHERE Username = ' " + textuser.Text + "'"
Dim myCommand As New MySqlCommand
myCommand.Connection = conn
myCommand.CommandText = sqlquery
myAdpter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()
If myData.HasRows Then
MsgBox("User exists!!")
Else
conn.Open()
Dim registerfinal As New MySqlDataAdapter
sqlquery = "INSERT INTO member (Username,Password) VALUES ('" + textuser.Text + "','" + textpass.Text + "')"
myCommand.Connection = conn
myCommand.CommandText = sqlquery
registerfinal.SelectCommand = myCommand
myData = myCommand.ExecuteReader
MsgBox("สมัครสมาชิกเรียบร้อย")
textuser.Clear()
textpass.Clear()
Me.Hide()
End IF