Option Strict On disallows operands of type Object for operator '<>'. Use the 'Is' operator to test for object identity.

Posted on 2006-10-28
Last Modified: 2013-11-19
<%@ Page Language="VB" Explicit="True" Strict-"True" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
      Public Sub btnLogin_Click(sender As Object, e As EventArgs)
            If Not Page.IsPostBack Then
                  Exit Sub
            End If
          Dim con As SqlConnection
          Dim cmd As SqlCommand
          Dim rdr As SqlDataReader
          Dim str As String
        Dim booOk As Boolean = False

          con = New SqlConnection("Data Source=;User ID=fffff;Password=fffff;Initial Catalog=ccccc")
            str = "Select * FROM tblUsers WHERE username = '" & txtUsername.Value & "' "
            cmd = New SqlCommand(str, con)
              rdr = cmd.ExecuteReader
                        If Not rdr.Read Then
                        lblErrMsg.Text = "Enter a valid User ID!"
                    ElseIf rdr.Item("Password") <> txtPassword.Value Then
                        lblErrMsg.Text = "Password is incorrect!"
                             booOk = True
                    End If                 


        If booOk Then
            FormsAuthentication.RedirectFromLoginPage(txtUsername.Value ,False)
        End If
    End Sub

    <link rel="stylesheet" type="text/css" href="KB/inc/Format.css">
      <title>IT Knowledge Base</title>
    <form method="post" runat="server">
        <h1 align="center">
              IT Knowledge Base
            <table class="normalbold" width="350" border="0" cellspacing="0" cellpadding="10" align="center" bgcolor="#cccccc">
                <tr align="left">
                    <td valign="top">
                    <td valign="top">
                          <input type="text" id="txtUsername" runat="server"></input>
                <tr align="left">
                    <td valign="top">
                    <td valign="top">
                          <input type="text" id="txtPassword" runat="server"></input>
                    <td colspan="3" align="center">
                        <asp:Label ID="lblErrMsg" Runat="Server" CssClass="err" Visible="True"/>
                        <input type="submit" id="btnLogin" value="Login" OnServerClick="btnLogin_Click" runat="server"></input>


When I run the webpage I get the following error:

BC32013: Option Strict On disallows operands of type Object for operator '<>'. Use the 'Is' operator to test for object identity.

It is referring to the statement that has 'ElseIf rdr.Item("Password") <> txtPassword.Value Then'


So I looked up the IsNot command and replaced the <> with it and got this error:

Option Strict On disallows implicit conversions from 'System.Object' to 'Boolean'.


What is my best bet to do?  rdr.Item and txtPassword will return a string and not a boolean wouldnt it?  But the result of the comparison would return a boolean?  Please help.  Thanks.

Question by:molard
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17825849
what about this:

 ElseIf NOT( rdr.Item("Password") = txtPassword.Value) Then

Author Comment

ID: 17825885
Thanks for the quick reply!

It gives me the following error:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC32013: Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object identity.

Source Error:


Line 25:                         If Not rdr.Read Then
Line 26:                         lblErrMsg.Text = "Enter a valid User ID!"
Line 27:                     ElseIf NOT rdr.Item("Password") = txtPassword.Value) Then
Line 28:                         lblErrMsg.Text = "Password is incorrect!"
Line 29:                     Else

I know that I can turn Option Strict off and it will work fine.  I wanted to get it working with Option Strict since I already have my other pages working fine with it.


I tried to take the advice it gave me and replace the = with Is.  It wouldnt let me log in and told me the Password is incorrect which references to those same lines of code.  Do you know anything else I might could try?  Thanks again!

Author Comment

ID: 17825892
I tried it exactly the way you posted which was:

ElseIf NOT( rdr.Item("Password") = txtPassword.Value) Then

and I also took out the ( ) on the outside and tried it.  It gave me the same error.
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17825903

ElseIf NOT( rdr.Item("Password").Value = txtPassword.Value) Then
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 50 total points
ID: 17825905
resp use the toString():

ElseIf NOT( rdr.Item("Password").toString() = txtPassword.Value.toString()) Then

Author Comment

ID: 17825920
The statement:

ElseIf NOT( rdr.Item("Password").toString() = txtPassword.Value.toString()) Then

worked great!  Thanks for your help!

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question