Sunday, October 13, 2013

Login

If you will create Login, you can use this script :

Imports MySql.Data.MySqlClient
Private Sub cmbOK_Click(sender As Object, e As EventArgs) Handles cmbOK.Click
        Dim conn As MySqlConnection

        'Connect to the database using these credentials
        conn = New MySqlConnection
        conn.ConnectionString = "Data Source=127.0.0.1;Database= namedatabase;User ID=name user;Password= password;"

        'Try and connect (conn.open)
        Try
            conn.Open()

        Catch myerror As MySqlException 'If it fails do this... (i.e. no internet or intranet connection, etc.)
            MsgBox("Error connecting to database. Check your internet / intranet connection.", MsgBoxStyle.Critical)
        End Try


        'MySQL query (where to call for information)
        Dim myAdapter As New MySqlDataAdapter

        'Tell where to find the file with the emails/passes stored
        Dim sqlquery = "SELECT * FROM userid WHERE UserID = '" & txtUserID.Text & "' AND Password = '" & txtPassword.Text & "'"
        Dim myCommand As New MySqlCommand
        myCommand.Connection = conn
        myCommand.CommandText = sqlquery

        'Start query
        myAdapter.SelectCommand = myCommand
        Dim myData As MySqlDataReader
        myData = myCommand.ExecuteReader

        'See if the user exists
        If myData.HasRows = 0 Then
            MsgBox("Invalid user id or password.", MsgBoxStyle.Critical)

            'Insert your settings change here. (i.e. My.Settings.LoggedIn = False)

        Else
            MsgBox("Logged in as " & txtUserID.Text & ".", MsgBoxStyle.Information)
            'MDIParent1.gcUserID = txtUserID.Text
            MDIParent1.ToolStripStatusLabel.Text = "Logged in as : " & txtUserID.Text
            'Another settings change: My.Settings.LoggedIn = True

            Me.Close() 'close the login form    End Sub
        End If

End Sub

No comments:

Post a Comment