1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
   | Imports MySql.Data.MySqlClient
 
Public Class LoginForm1
 
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
 
        Dim conn As MySqlConnection
        conn = New MySqlConnection()
        conn.ConnectionString = "server=localhost; user id=root; password=; database=cnx_user"
 
        Try
            conn.Open()
        Catch myerror As MySqlException
            MsgBox("error connecting to database")
        End Try
        Dim myAdapter As New MySqlDataAdapter
        Dim sqlquery = "SELECT * FROM cnx_user Where login = '" + txt_login.Text + "' AND password '" + txt_password.Text
        Dim myCommand As New MySqlCommand()
        myCommand.Connection = conn
        myCommand.CommandText = sqlquery
        myAdapter.SelectCommand = myCommand
        Dim myData As MySqlDataReader
        myData = myCommand.ExecuteReader
        If myData.HasRows = 0 Then
            MsgBox("Invalide Login !")
        Else
            MsgBox("login accepted")
            Form1.Show()
            Me.Hide()
        End If
        Me.Close()
    End Sub
 
    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub
 
End Class | 
Partager