By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,991 Members | 1,917 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,991 IT Pros & Developers. It's quick & easy.

Need help with login form

P: 62
i am connecting to access database(accdb) and created log in form in vb.net.Even if i type correct username.password and role it shows unauthorized user.
i am having this code on my log in button
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub btnloginlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnloginlogin.Click
  3.  
  4. Try
  5. 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;")
  6.             If con.State = ConnectionState.Closed Then
  7.                 con.Open()
  8.             End If
  9.             com = New OleDbCommand("SELECT * from tbllogin WHERE [User Name]='" & txtloginusname.Text & " ' And Password = ' " & txtloginpassword.Text & " ' And [Application/Role] = ' " & cmbloginrole.Text & " '", con)
  10.             ds = New DataSet
  11.             dap = New OleDbDataAdapter(com)
  12.             dap.Fill(ds, "tbllogin")
  13.             If con.State = ConnectionState.Open Then
  14.                 con.Close()
  15.             End If
  16.             If ds.Tables(0).Rows.Count() <> 0 Then
  17.                 If cmbloginrole.Text = "Administrator" Then
  18.                     AdministratorHomePage.Show()
  19.                     Me.Hide()
  20.                 Else
  21.                     MsgBox("UNAUTHORIZED USER")
  22.                     txtloginusname.Text = ""
  23.                     txtloginpassword.Text = ""
  24.                     cmbloginrole.Text = ""
  25.                 End If
  26.             Else
  27.                 MsgBox("UNAUTHORIZED USER")
  28.                 txtloginusname.Text = ""
  29.                 txtloginpassword.Text = ""
  30.                 cmbloginrole.Text = ""
  31.             End If
  32.  
  33.         Catch ex As Exception
  34.  
  35.             MsgBox(ex.Message)
  36.  
  37.         End Try
  38.  
  39.     End Sub
  40. End Class
  41.  
Feb 6 '14 #1
Share this Question
Share on Google+
3 Replies


100+
P: 299
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:
http://www.connectionstrings.com/access-2007/
Feb 6 '14 #2

100+
P: 294
Why aren't you using
Expand|Select|Wrap|Line Numbers
  1. Dim
to declare new variables? Also, check your DataSet and DataAdapter.
Are you sure
Expand|Select|Wrap|Line Numbers
  1. ds.Tables(0).Rows.Count
is pointing to the correct fields? Is "0" the correct index?

Also, for your Textbox
Expand|Select|Wrap|Line Numbers
  1. cmbloginrole.Text = "Administrator"
It might be wise to trim the text in the text box. This can be done by a variable or
Expand|Select|Wrap|Line Numbers
  1. .Text.Trim
See here:
Expand|Select|Wrap|Line Numbers
  1.         Dim login As String
  2.         Dim msg As String
  3.  
  4.         login = txt1.Text.Trim
  5.         msg = "Good"
  6.  
  7.         If login = "admin" Then
  8.             txt2.Text = msg
  9.         End If
I hope this helps you in some way.
Feb 6 '14 #3

P: 5
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
Feb 7 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.