Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27196

VS 2010 Need Coding Help to edit my login form

$
0
0
This project (code) is working correctly, in order to make it perfect I want to do some adjustments. I want to insert error messages for each textbox and combo box, that is I want to put error message for username, password and user_type, but the below code gives the error only to username and password. I want each one of it to give different error messages so that my objective of validation stated in the project synopsis is verified. I hope you get it.
And also I want to put a set focus to each input box (i.e. username, password and user_type) so that when the user_type is entered correctly, it will automatically go(focus) to the next input box that is the username and after that it will go to the next one that is password.
Thank you I hope its clear, below shows thee code and the interface. Please help me to make my project better!


Code:

Imports System.Data.OleDb
Public Class Login_Form
    Dim conn As New OleDbConnection
    Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
        If Me.cmbUser_Type.Text = "" Or Me.txtUsername.Text = "" Or Me.txtPassword.Text = "" Then Exit Sub
        If conn.State = 1 Then conn.Close()
        conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\user\Documents\Visual Studio 2010\Projects\Bakery Payroll System - Nayomi's\Username_Password.accdb"
        conn.Open()
        Dim sqlQRY As String = "SELECT * FROM Username_Password WHERE User_Type=' " & Me.cmbUser_Type.Text & "' AND Username = '" & Me.txtUsername.Text & "' AND Password = '" & Me.txtPassword.Text & "'"
        Dim cmd As OleDbCommand = New OleDbCommand(sqlQRY, conn)
        Dim rdr As OleDbDataReader = cmd.ExecuteReader
        rdr.Read()

        Dim sqlQRY1 As String = "SELECT * FROM Username_Password WHERE User_Type = '" & Me.cmbUser_Type.Text & "' AND Username = '" & Me.txtUsername.Text & "' AND Password = '" & Me.txtPassword.Text & "'"
        Dim cmd1 As OleDbCommand = New OleDbCommand(sqlQRY1, conn)
        Dim rdr1 As OleDbDataReader = cmd1.ExecuteReader
        rdr1.Read()
        If rdr.HasRows = True Then
            Dim User_Type As String = rdr("User_Type").ToString
            Dim Username As String = rdr("Username").ToString
            Dim Password As String = rdr("Password").ToString

            MsgBox("Welcome,You have succesfully logged in!")
            Form1.Show()
            Me.Hide()

        ElseIf rdr1.HasRows = True Then
            Dim User_Type As String = rdr1("User_Type").ToString
            Dim Username As String = rdr1("Username").ToString
            Dim Password As String = rdr1("Password").ToString

            MsgBox("Welcome,You have succesfully logged in!")
            Form1.Show()
            Me.Hide()

        Else

            MessageBox.Show("Invalid Password or Username", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
    End Sub


 Private Sub Login_Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cnString As String

        cnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Username_Password.accdb"
        'Create connection
        conn = New OleDbConnection(cnString)

        Try
            ' Open connection
            conn.Open()
        Catch ex As OleDbException
            MessageBox.Show(ex.Message, "Error..", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            ' Close connection
            'conn.Close()
        End Try
        cmbUser_Type.Text = ""
        txtUsername.Text = ""
        txtPassword.Text = ""
    End Sub

Name:  login form.JPG
Views: 153
Size:  146.5 KB
Attached Images
 

Viewing all articles
Browse latest Browse all 27196

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>