Need help with login form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahul2310
    New Member
    • Oct 2013
    • 62

    Need help with login form

    i am connecting to access database(accdb) and created log in form in vb.net.Even if i type correct username.passwo rd and role it shows unauthorized user.
    i am having this code on my log in button
    Code:
    Private Sub btnloginlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnloginlogin.Click
    
    Try
    con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database1.accdb;Persist Security Info=False;")
                If con.State = ConnectionState.Closed Then
                    con.Open()
                End If
                com = New OleDbCommand("SELECT * from tbllogin WHERE [User Name]='" & txtloginusname.Text & " ' And Password = ' " & txtloginpassword.Text & " ' And [Application/Role] = ' " & cmbloginrole.Text & " '", con)
                ds = New DataSet
                dap = New OleDbDataAdapter(com)
                dap.Fill(ds, "tbllogin")
                If con.State = ConnectionState.Open Then
                    con.Close()
                End If
                If ds.Tables(0).Rows.Count() <> 0 Then
                    If cmbloginrole.Text = "Administrator" Then
                        AdministratorHomePage.Show()
                        Me.Hide()
                    Else
                        MsgBox("UNAUTHORIZED USER")
                        txtloginusname.Text = ""
                        txtloginpassword.Text = ""
                        cmbloginrole.Text = ""
                    End If
                Else
                    MsgBox("UNAUTHORIZED USER")
                    txtloginusname.Text = ""
                    txtloginpassword.Text = ""
                    cmbloginrole.Text = ""
                End If
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
    
            End Try
    
        End Sub
    End Class
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    Your code doesn't actually show as you trying to pass credentials (specifically a password) to access the database. In your connection string you need to include a password if the database has one. Here is website that has a list of proper connection strings for you:
    Connection strings for Access 2007. Connect using Microsoft.ACE.OLEDB.12.0, OleDbConnection, Microsoft Access accdb ODBC Driver and ODBC .NET Provider.

    Comment

    • mcupito
      Contributor
      • Aug 2013
      • 294

      #3
      Why aren't you using
      Code:
      Dim
      to declare new variables? Also, check your DataSet and DataAdapter.
      Are you sure
      Code:
      ds.Tables(0).Rows.Count
      is pointing to the correct fields? Is "0" the correct index?

      Also, for your Textbox
      Code:
      cmbloginrole.Text = "Administrator"
      It might be wise to trim the text in the text box. This can be done by a variable or
      Code:
      .Text.Trim
      See here:
      Code:
              Dim login As String
              Dim msg As String
      
              login = txt1.Text.Trim
              msg = "Good"
      
              If login = "admin" Then
                  txt2.Text = msg
              End If
      I hope this helps you in some way.
      Last edited by mcupito; Feb 6 '14, 03:25 PM. Reason: More info

      Comment

      • sagarrupani
        New Member
        • Feb 2014
        • 5

        #4
        hy rahul if you Checking "username" and "password" manually than why using OLEDB connection and command..first try with DRY RUN with STATIC VALUE.

        Hope you got my reply.

        Have a happy coding

        Comment

        Working...