Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27343

VS 2010 [RESOLVED] Problem with datareader

$
0
0
I have a login form which is connected to a database, and i currently have a data reader to make sure that i enter the correct username and password, by using this code:

Dim dr As OleDbDataReader

Try
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * FROM Users WHERE Username= user AND [Password]= pword"

Dim cmd As OleDbCommand = New OleDbCommand(sql, con)

cmd.Parameters.AddWithValue("Username", user)

cmd.Parameters.AddWithValue("Password", pword)

dr = cmd.ExecuteReader


'the following two lines are from module1
LoggedinUserLevel = DReader("SecurityLevel")

LoggedinUser = DReader("Username")

Catch errObj As Exception
MessageBox.Show(errObj.Message)
End Try

End If

' If dr.Read() = True And user = dr("Username").ToString And pword = dr("Password").ToString Then

If dr.Read() = True Then
MsgBox("Welcome back !")
Else
MsgBox("Login Failure")


con.Close()
dr.Close()

End If

but a warning sign appears:

"Variable 'dr' is used before it has been assigned a value. A null reference exception could result at runtime."

After I use the login form the program stops,

If any can help me, it would be greatly appreciated.

Viewing all articles
Browse latest Browse all 27343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>