Guest User

Untitled

a guest
Feb 2nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  2.  
  3. End Sub
  4.  
  5. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  6. ConnectToSQL()
  7. End Sub
  8.  
  9. 'connecting to sql method
  10. Private Sub ConnectToSQL()
  11. Dim con As New MySqlConnection
  12. Dim cmd As New MySqlCommand
  13. Dim StudentId As String
  14. Dim StudentPassword As String
  15.  
  16. Try
  17.  
  18. If con.ConnectionString = "Data source= localhost; port=3306; database= Students; user=root; password=;" Then
  19. con.Open()
  20.  
  21. cmd.Connection = con
  22. cmd.CommandText = "SELECT StudentId, StudentPassword, StudentName FROM members"
  23.  
  24. Dim lrd As MySqlDataReader = cmd.ExecuteReader()
  25. If lrd.HasRows Then
  26. While lrd.Read()
  27. StudentId = lrd("StudentId").ToString
  28. StudentPassword = lrd("StudentPassword").ToString
  29. If StudentPassword = TextBox1.Text And StudentId = TextBox1.Text Then
  30. MsgBox("you logged in succesfully")
  31. Me.Hide()
  32. Form2.Show()
  33.  
  34. TextBox1.Text = ""
  35. TextBox2.Text = ""
  36. End If
  37.  
  38. End While
  39.  
  40. Else
  41. MsgBox("Username and password do not match")
  42. TextBox2.Text = ""
  43. End If
  44. End If
  45.  
  46. Catch ex As Exception
  47. MsgBox(ex.Message)
  48.  
  49. Finally
  50. con.Close()
  51. End Try
  52. End Sub
  53.  
  54. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  55. TextBox1.Text = ""
  56. TextBox2.Text = ""
  57. TextBox1.Focus()
  58. End Sub
Add Comment
Please, Sign In to add comment