Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         Dim conn As MySqlConnection
  2.         'connect to DB
  3.        conn = New MysqlConnection()
  4.         conn.ConnectionString = "server=yourwebsitehere.com; user id=your_username_here; password=your_password_here; database=yourdatabase_namehere"
  5.         'see if connection failed.
  6.        Try
  7.             conn.Open()
  8.         Catch myerror As MySqlException
  9.             MsgBox("Error connecting to database!")
  10.         End Try
  11.         'sql query
  12.        Dim myAdapter As New MySqlDataAdapter
  13.  
  14.         Dim sqlquery = "SELECT * FROM login WHERE username='" + txtuser.Text + "' AND password= '" + txtpass.Text + "'"
  15.         Dim myCommand As New MySqlCommand()
  16.         myCommand.Connection = conn
  17.         myCommand.CommandText = sqlquery
  18.         'start query
  19.        myAdapter.SelectCommand = myCommand
  20.         Dim myData As MySqlDataReader
  21.         myData = myCommand.ExecuteReader()
  22.         'see if user exists
  23.        If myData.HasRows = 0 Then
  24.             MsgBox("Invalid username and/or password!")
  25.         Else
  26.             MsgBox("Login Accepted!")
  27.             Form1.Show()
  28.             Me.Hide()
  29.         End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement