Results 1 to 5 of 5

Thread: [RESOLVED] Oledb Login Form

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,390

    Resolved [RESOLVED] Oledb Login Form

    I'm making a window's application project, and I'm trying to make a login page. First time trying, and I think I'm getting somewhere. Just keep running into a few things. Here is my code:
    Code:
    Imports System.Data.OleDb
    
    Public Class Form4
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim msg As String
            Dim title As String
            Dim style As MsgBoxStyle
            Dim response As MsgBoxResult
            msg = "Do you want to not login?"
            style = MsgBoxStyle.DefaultButton2 Or _
               MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
            title = "?"
            response = MsgBox(msg, style, title)
            If response = MsgBoxResult.Yes Then
                Me.Close()
                If response = MsgBoxResult.No Then
                    IDTextBox.Clear()
                    PasswordTextBox.Clear()
                End If
            End If
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
    
                Dim na As String
                Dim ne As String
                Dim ni As String
                Dim read As OleDbDataReader
    
                Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= ./login.mdb;Jet OLEDB")
                Dim cmd As OleDbCommand = New OleDbCommand("Select * from login where First_NameTextBox.Text = '" & PasswordTextBox.Text & "' ", cn)
    
    
                cn.Open()
    
                read = cmd.ExecuteReader
                If read.HasRows Then
                    read.Read()
                    na = read("AdminName")
                    ni = read("AdminPass")
                    If (First_NameTextBox.Text = na And PasswordTextBox.Text = ni) Then ne = na
    
                    Form1.Show()
    
    
    
                    Me.Hide()
                Else
                    MsgBox("Incorrect Username/Password")
                    First_NameTextBox.Clear()
                    PasswordTextBox.Clear()
    
                End If
            Catch
                MsgBox("Error logging in, please try again", MsgBoxStyle.Exclamation)
            End Try
    
        End Sub
    End Class
    The problems I run into are:

    my textbox.clear isn't clearing. The text stays
    when I try debugging the program and enter my first name and password, it gives me the "error logging in, please try again" and I know that test/test is the first name and password :P is there anything you notice that I should do?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Oledb Login Form

    your select statement is wrong. it should be something like this:

    vb Code:
    1. "SELECT * FROM login WHERE fieldName = '" & First_NameTextBox.Text & "' AND otherFieldName = '" & PasswordTextBox.Text & "'"

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,390

    Re: Oledb Login Form

    In the sql statement, is it [first name] or first_name for the field name?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Oledb Login Form

    Quote Originally Posted by .paul. View Post
    your select statement is wrong. it should be something like this:

    vb Code:
    1. "SELECT * FROM login WHERE fieldName = '" & First_NameTextBox.Text & "' AND otherFieldName = '" & PasswordTextBox.Text & "'"
    Heck, I'll go a step further an throw in parameters....
    vb Code:
    1. "SELECT * FROM login WHERE fieldName = ? AND otherFieldName = ?"
    Then use the .Parameters.AddWithValue method to add the values... just be sure to do it in the right order.

    If you want to know why you should use parameters... you never know when Bobby Drop Tables will try to login - http://xkcd.com/327/

    Quote Originally Posted by dday9 View Post
    In the sql statement, is it [first name] or first_name for the field name?
    Huh? You tell us... it's your table structure... not ours...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,390

    Re: Oledb Login Form

    Huh? You tell us... it's your table structure... not ours...
    I thought that you had to do [first name] in oledb if there's a space in your field name. But it's w/e I just added a loginform and added this:
    Code:
        Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
            If Me.UsernameTextBox.Text = "admin" And Me.PasswordTextBox.Text = "admin" Then
    
                Form1.Show()
    
                Me.Close()
    
            Else
    
                MsgBox("Invalid username or password.")
    
                PasswordTextBox.Text = ""
    
                UsernameTextBox.Select(0, UsernameTextBox.Text.Length())
    
            End If
        End Sub
    
        Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
            Me.Close() '***** msgboxes!
        End Sub
    If I have any other questions, I'll just post another thread. Thanks
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width