Hy guys,
Please assist in advcicing which toolbox connection controls to add in my form. I want to connect to access 2007 using vb.net 2005 and im struggling. I have two textboxes(username and password) and two buttons(submit and cancel). When I click on the submit button it supposed to allow the user to logon to the system, but it dsnt…my connection string is
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Video Rental System\DvDSystem1.accdb
Which is fine(I think). I can’t get the congurations right for thelogin form in desing view (properties window)
.I need urgent assistance pls help
Here is my code below

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim conn As OleDb.OleDbConnection
Dim cmd As OleDb.OleDbCommand 
Dim selectQuery As String
Dim dr As OleDb.OleDbDataReader
Dim userProfile As String
Try
conn = New OleDb.OleDbConnection"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Video Rental System\DvDSystem1.accdb")
conn.Open()
selectQuery = "SELECT * FROM USERR WHERE userID = '" & txtUsername.Text & "' AND userPassword = '" & txtPassword.Text & "'"
cmd = New OleDb.OleDbCommand(selectQuery, conn)
dr = cmd.ExecuteReader
'if successfull then log in
If dr.Read Then
'Get user profile
userProfile = dr.GetString(3)
keptProfile = userProfile
If keptProfile = "admin" Then
MainrMenur.Show()
End If
EseIf txtUsername.Text <> "" Then
If txtPassword.Text <> "" Then
MessageBox.Show("Wrong login, please try again ...", "Login Denied", MessageBoxButtons.OK)
Else
MessageBox.Show("Please enter password", "Login Error", MessageBoxButtons.OK)
txtPassword.Focus()
End If
Else
MessageBox.Show("Please enter user id", "Login Error", MessageBoxButtons.OK)
txtUsername.Focus()
End If
'Clear password field after login
txtPassword.Clear()
catch ex As Exception
MessageBox.Show("Please exit system and login again.", "Login Error", MessageBoxButtons.OK)
End Try
'conn.Close()
Me.Close()
End Sub

Recommended Answers

All 8 Replies

Are you getting any errors when you run it and, if so, what are they?

Im getting the following error:
MessageBox.Show("Please exit system and login again.", "Login Error", MessageBoxButtons.OK)

OK, catch the actual exception, ex.Message, and see what that says.
Naturally, "please exit system..." is the error message you supplied.

I could do with some help...ive been trying to coonect for almost 2 months plz assist

Well, getting the actual error message would be a fantastic place to start.
Change this:

catch ex As Exception
MessageBox.Show("Please exit system and login again.", "Login Error", MessageBoxButtons.OK)
End Try

To

catch ex As Exception
MessageBox.Show(ex.Message, "Login Error", MessageBoxButtons.OK)
End Try

This will give you the real reason for entring tha catch block and we might be able to figure it out.

I've just gone over your code properly and it could use a couple of pointers.
1) You're putting user input directly into you sql query. Bad idea, use parameters instead.
2) You check for whether the user name and password have been entered AFTER trying to get a result from the database

Neither of those things would cause the code to crash though.

ive changed the catch statement to:

Catch ex As Exception
MsgBox(ex.Message)
end try

And now it says"No value for one or more required parameters"

Any advice on where i can make changes to my code?

got the answer...what i had to do was put [] brackets in fields with spaces.

thanks guys for all your efforts..really appreciate it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.