SHARE
TWEET

login

a guest May 21st, 2019 149 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports MySql.Data.MySqlClient
  2.  
  3. Public Class Form1
  4.  
  5.     Dim conn As MySqlConnection
  6.     Dim command As MySqlCommand
  7.     Dim reader As MySqlDataReader
  8.  
  9.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  10.         conn = New MySqlConnection
  11.         conn.ConnectionString =
  12.             "server=localhost;user=root;password=;database=vb_login;sslMode=none"
  13.  
  14.         Try
  15.             conn.Open()
  16.             MessageBox.Show("Sukses")
  17.             conn.Close()
  18.         Catch ex As Exception
  19.             MessageBox.Show(ex.Message)
  20.         Finally
  21.             conn.Dispose()
  22.         End Try
  23.  
  24.     End Sub
  25.  
  26.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  27.         conn = New MySqlConnection
  28.         conn.ConnectionString =
  29.             "server=localhost;user=root;password=;database=vb_login;sslMode=none"
  30.  
  31.         Dim query As String =
  32.             "select * from user where username = '" & TextBox1.Text & "' and password = '" & TextBox2.Text & "'"
  33.  
  34.         Try
  35.             conn.Open()
  36.             command = New MySqlCommand(query, conn)
  37.             reader = command.ExecuteReader
  38.  
  39.             Dim count As Integer = 0
  40.             Dim name As String = ""
  41.  
  42.             While reader.Read
  43.                 count = count + 1
  44.                 name = reader.GetValue(1).ToString().Trim()
  45.             End While
  46.  
  47.             If count = 0 Then
  48.                 MessageBox.Show("Username/Password tidak valid")
  49.             ElseIf count > 1 Then
  50.                 MessageBox.Show("Username duplikat")
  51.             Else
  52.                 MessageBox.Show("Selamat datang " & name)
  53.             End If
  54.  
  55.             conn.Close()
  56.         Catch ex As Exception
  57.             MessageBox.Show(ex.Message)
  58.         Finally
  59.             conn.Dispose()
  60.         End Try
  61.     End Sub
  62. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top