Advertisement
Guest User

Untitled

a guest
Mar 16th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. Private Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
  2. Conn = New MySqlConnection
  3. Conn.ConnectionString = "server=localhost;userid=root;password=mmmsss123;database=gymdb"
  4.  
  5. txtUName.Text = txtUName.Text.ToLower()
  6. txtUName.Text = txtUName.Text.Replace(" ", "")
  7. txtPassword.Text = txtPassword.Text.ToLower()
  8. txtPassword.Text = txtPassword.Text.Replace(" ", "")
  9.  
  10. Try
  11. Conn.Open()
  12. Dim Query As String
  13. Query = "select * from gymdb.user where username='" & txtUName.Text & "'"
  14. Cmd = New MySqlCommand(Query, Conn)
  15. Cmd.ExecuteNonQuery()
  16. Rdr = Cmd.ExecuteReader
  17.  
  18. Dim Count As Integer = 0
  19.  
  20. While Rdr.Read
  21. Count += 1
  22. End While
  23. Rdr.Close()
  24.  
  25. Conn.Close()
  26.  
  27. If Count >= 1 Then
  28. MessageBox.Show("This Username Is Already Registered!" & Environment.NewLine & "Please Enter Another Username", "Registeration State")
  29. Else
  30. If txtUName.Text <> "" And txtPassword.Text <> "" Then
  31. Conn.Open()
  32. Query = "insert into gymdb.user (username, upassword) values ('" & txtUName.Text & "', '" & txtPassword.Text & "')"
  33. Cmd1 = New MySqlCommand(Query, Conn)
  34. MessageBox.Show("Registered Successfully!", "Registeration State")
  35. Conn.Close()
  36. Else
  37. MessageBox.Show("Not Valid Username Or Password!" & Environment.NewLine & "Please Enter Valid Username And Password", "Registeration State")
  38. End If
  39. End If
  40.  
  41. Catch ex As MySqlException
  42. MessageBox.Show(ex.Message, "Error!")
  43. Finally
  44. Conn.Dispose()
  45. End Try
  46. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement