Dim conn As MySqlConnection
conn = New MySqlConnection
conn.ConnectionString = "server=localhost; user id=root; password=bossza; database=bossza"
Try
conn.Open()
Catch myerror As MySqlException
MsgBox("ไม่สามารถเชื่อต่อเซฟเวอร์ได้")
End Try
Dim myAdpter As New MySqlDataAdapter
Dim sqlquery = "SELECT FROM * members 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 members (Username,Password) VALUES ('" + textuser.Text + "','" + textpass.Text + "')"
myCommand.Connection = conn
myCommand.CommandText = sqlquery
registerfinal.SelectCommand = myCommand
myData = myCommand.ExecuteReader
MsgBox("สมัครสมาชิกเรียบร้อย")
Me.Hide()
Else
MsgBox("มีคนใช้ Username นี้แล้ว'")
End If