Solved

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

Posted on 2006-10-28
6
1,217 Views
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=9.9.9.9;User ID=fffff;Password=fffff;Initial Catalog=ccccc")
            con.Open
            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!"
                    Else
                             booOk = True
                    End If                 

                  rdr.Close
                cmd.Dispose
                con.Close


        If booOk Then
            FormsAuthentication.RedirectFromLoginPage(txtUsername.Value ,False)
        End If
    End Sub
</script>


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

==================================

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.

0
Comment
Question by:molard
  • 3
  • 3
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
what about this:

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

Author Comment

by:molard
Comment Utility
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!
0
 

Author Comment

by:molard
Comment Utility
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility

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

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
Comment Utility
resp use the toString():

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

Author Comment

by:molard
Comment Utility
The statement:

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

worked great!  Thanks for your help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now