SHARE
TWEET

Untitled

a guest Oct 4th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports MySql.Data.MySqlClient
  2.  
  3. Public Class login
  4.     Dim myconn As New MySqlConnection("Server=" + My.Settings.databasehost + ";User Id=" + My.Settings.databaseid + ";Password=" + My.Settings.databasepass + ";Database=" + My.Settings.database)
  5.  
  6.     Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  7.         Try
  8.             myconn.Open()
  9.  
  10.             ToolStripStatusLabel1.Text = "Connection to database was successful"
  11.             myconn.Close()
  12.  
  13.         Catch ex As Exception
  14.             MessageBox.Show(ex.Message)
  15.             ToolStripStatusLabel1.Text = "Connection to database failed"
  16.  
  17.  
  18.         End Try
  19.        
  20.     End Sub
  21.  
  22.     Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
  23.         Application.Exit()
  24.  
  25.     End Sub
  26.  
  27.     Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
  28.         Try
  29.             If txtUsername.Text = "" Or txtPassword.Text = "" Then
  30.                 MsgBox("Please enter a username/password")
  31.             Else
  32.                 Dim myAdapter As New MySqlDataAdapter("SELECT * FROM users WHERE username= " & txtUsername.Text, myconn)
  33.                 Dim myDataTable As New DataTable
  34.                 myAdapter.Fill(myDataTable)
  35.                 If myDataTable.Rows.Count > 0 Then
  36.                     If txtUsername.Text = myDataTable.Rows(0).Item("username") And txtPassword.Text = myDataTable.Rows(0).Item("password") Then
  37.                         MsgBox("Good day " + myDataTable.Rows(0).Item("fname"))
  38.                         Me.Close()
  39.                         Form1.Enabled = True
  40.  
  41.                     Else
  42.                         MsgBox("Incorrect Username/Password")
  43.                     End If
  44.                 End If
  45.             End If
  46.  
  47.         Catch ex As Exception
  48.             MessageBox.Show(ex.Message)
  49.  
  50.         End Try
  51.             End Sub
  52. 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