1.11M Members

Login Page Database connection to MSAccess

 
0
 

I been working on this login page for months, and to no avail can have the program working. I am using the MSAccess Database and using VB.Net. This is a windows application creating a login page. The following is the code that I been working on:
Dim mypath = Application.StartupPath & "\password.mdb"
Dim Password = ""
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Documents and Settings\Owner\My Documents\OLEDB\password.mdb")
Dim cmd As OleDbCommand

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim sql = "SELECT Username,Password FROM Password WHERE Username = '" & txtUsername.Text & "' AND Password = '" & txtPassword.Text & "'"

cmd = New OleDbCommand(sql, conn)
Dim dr As OleDbDataReader = cmd.ExecuteReader


Try
conn.Open()

Catch ex As InvalidOperationException
MsgBox(ex.Message)

End Try
Try
If dr.Read = False Then
MessageBox.Show("Authentication Failed...")
Else
MessageBox.Show("Login Successful...")

End If
Catch ex As Exception
MsgBox(ex.Message)

End Try

If conn.State <> ConnectionState.Closed Then
conn.Close()

End If


Dim form As New Form2
form.Show()

End Sub

The above code generates an error that points to the cmd.ExecuteReader
It says that the error : "ExecuteReader requires an open connection and available connection. The connection's current state is closed."
How can I use the open state for the ExecuteReader?

 
0
 

OK well the error is telling you exactly what is wrong. ExecuteReader requires an open connection and available connection

You need to add this line of code before you ExecuteReader. conn.Open()


Hope this helps

 
0
 

OK well the error is telling you exactly what is wrong. ExecuteReader requires an open connection and available connection

You need to add this line of code before you ExecuteReader. conn.Open()


Hope this helps

I really did because I tried it, and was missing in my coding. It is fixed and running good. I just need to be caredful how i code. The error message really drove me crazy, and thanks to you developers that assisted me in correcting my code. I will practice more. Now I am trying to learn the Stored Procedures.
Find it difficult, but will continue on it.

 
0
 

Glad it worked

If you have troubles with Store Procedures or anything in SQL/Access just post on the forums, someone will be glad to help!

I really did because I tried it, and was missing in my coding. It is fixed and running good. I just need to be caredful how i code. The error message really drove me crazy, and thanks to you developers that assisted me in correcting my code. I will practice more. Now I am trying to learn the Stored Procedures.
Find it difficult, but will continue on it.

 
0
 

well i tried n it didn work.. wher shud i write tht code line??

 
-1
 

This codes works. I also need to fetch the user's full name and the account type into a variable, in order to be able to welcome the user by his full name. How do i do that? Thanx

 
0
 

how do i change background image on a command button at a runtime? Thanx

 
0
 

i guess you can do that in the form_load event.

Call the button in the load event

button1.image = (the path where you have the image of the button or place it in the bin)

 
0
 

I have a form (frmLogin) on which i have 4 command button n 1 is btnLogIn. so need to change the image on the btnLogIn after the user has logged In.

i had wanted to use something like imageList. Plz help
Thanx

 
0
 

[i have problem with that code could u plz send me the correct code to my e-mail id that is <snipped email> i will be very thankfull of you

 
0
 

place the

conn.Open() under the Try - Catch.. it will work

 
0
 

ok, well i no longer have the problem you guys have had. I don;t no what is wronge so ill ask you. ok the line

Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader

it apperes with the error "Syntax error in FROM clause"

Anyhelp were im going wronge?

Thanks

 
-1
 

Hello every one,

i have a database in SQL Server 2008 with some login--> User
how to connect to the database via registered Login or User from a VN.net application
how to creat a login form for it to access sql server registered logins--> user

thank you in advance

 
-1
 

open connection befor declaring the ExecuteReader
like this
Dim sql = "SELECT Username,password FROM Login WHERE Username = '" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'"
con.Open()
Dim cmd As OleDbCommand = New OleDbCommand(sql, con)

Dim dr As OleDbDataReader = cmd.ExecuteReader

 
0
 

Heading Here

Sub-Heading Here

  1. Item One
  2. Item Two
  3. Item Three
  • Item One
  • Item Two
  • Item Three

    Code blocks are created by indenting at least 4 spaces
    ... and can span multiple lines

    Inline Code Example Here Link Anchor Text

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article