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?

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

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.

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.

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

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

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

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)

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

[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

place the

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

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

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

commented: search the forum before posting. this has been answered multiple times -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

commented: you are only 4 years late. better reply to more recent threads. -3
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

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.