Guest User

Untitled

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