MbahAgis

Validasi KeyPress

Mar 16th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.25 KB | None | 0 0
  1. Private Sub txtUsername_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtUsername.KeyPress
  2.  
  3.         'tampung hasil query ke datatable
  4.         Dim DT As New DataTable
  5.         Using con As New MySqlConnection("server=localhost;database=tes;uid=root;pwd=root;")
  6.             Using adp As New MySqlDataAdapter("Select username, password From Login", con)
  7.                 Try
  8.                     adp.Fill(DT)
  9.                 Catch ex As Exception
  10.                     MsgBox(ex.ToString)
  11.                     Exit Sub
  12.                 End Try
  13.             End Using
  14.         End Using
  15.  
  16.         'validasi jika user menekan tombol enter di textbox username
  17.         If e.KeyChar = Chr(13) Then
  18.             If txtUsername.Text = "" Then
  19.                 MsgBox("Masukan username anda", vbInformation, "Kesalahan")
  20.                 txtUsername.Focus()
  21.             Else
  22.  
  23.                 'filter/seleksi datatable
  24.                 If DT.Select("username='" & txtUsername.Text & "' ").Count > 0 Then
  25.                     txtPassword.Focus()
  26.                 Else
  27.                     MsgBox("Username tidak ditemukan", vbInformation, "Kesalahan")
  28.                     txtUsername.Focus()
  29.                 End If
  30.             End If
  31.  
  32.         End If
  33.  
  34.  
  35.     End Sub
Add Comment
Please, Sign In to add comment