Wrox Programmer Forums
|
Forum and Wrox.com Feedback Post your suggestions for improving the Forums or Wrox.com or questions for the staff here. "Where can I find the code for my book?"
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Forum and Wrox.com Feedback section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 16th, 2008, 01:17 PM
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

  #2 (permalink)  
Old June 23rd, 2008, 11:36 PM
Registered User
 
Join Date: May 2007
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi

your program is correct one...

I) However it will be good (I think so..) if you check the username & password at storeprocedure level & return true or false. then no need of using this data reader.

II) You didn't mention what kind of error you are getting. without knowing that how can i help you.


If this helps you then please let me know.

Thanks
Anil Goyal

Regards

Anil Goyal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Login Logout Apocolypse2005 PHP Databases 1 September 25th, 2008 01:17 AM
Simple login but nothing happens... Ols Beginning PHP 2 July 29th, 2006 05:04 AM
Simple ASP.NET Membership Provider Login jumpseatnews ASP.NET 2.0 Basics 0 July 16th, 2006 10:53 AM
Simple Java Login Page skchbs Java GUI 0 October 9th, 2003 06:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.