The above code has been runtime Error display. Variable 'objReader' is used before it has been assigned a value. A null reference Exception could result at runtime. pls solve this error.
Error Line for: objReader.Close()
Protected Sub Login(ByVal sender As Object, ByVal e As System.EventArgs)
Dim intID As Integer = 0
Dim Conn As New OleDbConnection("Provider=" & _
"Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=userTable.mdb")
Dim objCmd As OleDbCommand = New OleDbCommand _
("SELECT UserID FROM tblUsers WHERE " & _
"Username = '" & tbUsername.Text & "' " & _
"AND Password = '" & tbPassword.Text & "'", Conn)
Dim objReader As OleDbDataReader
Try
objCmd.Connection.Open()
objReader = objCmd.ExecuteReader()
Do While objReader.Read
intID = objReader.GetInt32(0).ToString()
Loop
Catch ex As OleDbException
lblMessage.Text = ex.Message
Finally
objReader.Close()
objCmd.Connection.Close()
End Try
If intID <> 0 Then
FormsAuthentication.SetAuthCookie(intID, False)
lblMessage.Text = "Success!"
Else
lblMessage.Text = "Invalid username or password!"
End If
End Sub