Thread: simple Login
View Single Post
  #1 (permalink)  
Old June 16th, 2008, 01:17 PM
Nuwang Nuwang is offline
Registered User
 
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default simple Login

hi,

I have simple program to login access database
(no Password encryption)

But this give errors
how can I modify this for better
 
Quote:
quote:
Quote:
Imports System.Data
Imports System.Data.OleDb
Public Class frmLogin
    Inherits System.Windows.Forms.Form
    '---------------------------------------------------------
    Private strConnectionString As String = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=D:\Nuwan\Login\Loginbase.mdb;"

    Private objConnection As OleDbConnection
    Private objCommand As OleDbCommand
    Private objDataAdapter As OleDbDataAdapter
    Private objDataSet As DataSet

    Private objDataReader As OleDbDataReader
    '---------------------------------------------------------

    Dim Ctr As Integer
    Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
        'Dim LoginName As String, Password As String
        Dim flag As Boolean
        flag = False
        'LoginName = txtUserName.Text
        'Password = txtPassword.Text
        Ctr = Ctr + 1
        '----------------------------------------
        objConnection = New OleDbConnection(strConnectionString)
        objConnection.Open()

        'Initialize the Command object
        objCommand = New OleDbCommand

        'Set the objCommand object properties
        objCommand.CommandText = "LoginTable"
        objCommand.CommandType = CommandType.StoredProcedure
        objCommand.Connection = objConnection

        'Add the required parameter for the query
        objCommand.Parameters.Add("LoginNameD", OleDbType.Guid, 16).Value = _
            New Guid(txtUserName.Text)

        objDataReader = objCommand.ExecuteReader()

        'If we have data then display the project description
        If objDataReader.HasRows Then
            objDataReader.Read()
            '----------------------------------------
            If txtUserName.Text = objDataReader.Item("PasswordD") Then
                lblMessage.Text = "Welcome to Alarm Monitoring System Data Entry"
                Ctr = 0
                Dim frm As New Form2
                frm.Show()
            Else
                If Ctr < 3 Then
                    lblMessage.Text = "Incorrect User Name or Password - Please Try again"
                    txtUserName.Focus()
                Else
                    MsgBox("Unauthorized Access. Aborting...")
                    Close()
                End If
            End If
        End If
        '----------------------------------------
        'Close the DataReader and Connection
        objDataReader.Close()
        objConnection.Close()

        'Clean up
        objDataReader = Nothing
        objCommand.Dispose()
        objCommand = Nothing
        objConnection.Dispose()
        objConnection = Nothing
        '----------------------------------------
    End Sub
Thanx
Nuwan