I have 2 tables:
IDM_IDEA_USERS
USER_ID
PASSWORD
SAP_ID

IDM_IDEA_AUTHORIZED_USERS
SAP_ID

I need to retrieve information from table IDM_IDEA_USERS column name USER_ID and PASSWORD. I also need to verify that only SAP_ID from IDM_IDEA_USERS table is the same as SAP_ID from IDM_IDEA_AUTHORIZED_USERS. Only the users from IDM_IDEA_AUTHORIZED_USERS can login.

This are my codings.

Dim conn As New OleDbConnection(My.Settings.ConnectionString)
           Try
                conn.Open()
                Dim cmd As New OleDbCommand("Select Distinct * From IDM_IDEA_USERS and IDM_IDEA_AUTHORIZED_USERS Where IDM_IDEA_USERS.USER_ID=?, IDM_IDEA_USERS.PASSWORD=? and IDM_IDEA_USERS.SAP_ID = IDM_IDEA_AUTHORIZED_USERS.SAP_ID")

                cmd.Parameters.Add("@p1", OleDbType.VarChar, 20)
                cmd.Parameters("@p1").Value = Me.txtUser.Text.ToUpper

                cmd.Parameters.Add("@p2", OleDbType.VarChar, 20)
                cmd.Parameters("@p2").Value = Me.txtPass.Text

                Dim dr As OleDbDataReader
                dr = cmd.ExecuteReader

                If dr.HasRows = True Then
                    frmTrackIDEA.Show()
                Else
                    MsgBox("Invalid login!!Please check your username or password!", MsgBoxStyle.Exclamation, "INVALID")
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                conn.Close()
                'Me.Hide()
            End Try

after executing this, i got this error message:
ExecuteReader: Connection property has not been initialized.

How do i solve this?
I really hope u guys can help me.
Thanks

Recommended Answers

All 3 Replies

What exactly is your question?

I would change SQL to:

"Select Distinct * From IDM_IDEA_USERS, IDM_IDEA_AUTHORIZED_USERS Where IDM_IDEA_USERS.USER_ID=? and IDM_IDEA_USERS.PASSWORD=? and IDM_IDEA_USERS.SAP_ID = IDM_IDEA_AUTHORIZED_USERS.SAP_ID"

also, instead of "?"-characters you should have @p1 and @p2. I think, I didn't checked :)

Forget my previous post :angry: I found your question...

Add connection to command:

Dim cmd As New OleDbCommand("Select Distinct * From IDM_IDEA_USERS and IDM_IDEA_AUTHORIZED_USERS Where IDM_IDEA_USERS.USER_ID=?, IDM_IDEA_USERS.PASSWORD=? and IDM_IDEA_USERS.SAP_ID = IDM_IDEA_AUTHORIZED_USERS.SAP_ID", conn)

thx alot
=)

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.