Link to home
Start Free TrialLog in
Avatar of jchaplw
jchaplw

asked on

Using Visual Studio 2008 vb.net, string comparison failing because of leading double quote

New to Visual Studio and vb.net.  I am attempting to compare two string values.  One is returned from Oracle through the data reader and the other string is entered by the user through a text box user control.

As you can see from the attached screenshot, the string returned from Oracle has a leading double quote but no ending double quote.  I am assuming this is why the string comparison is failing?
 User generated image
Using the debugger tool, here's the HTML view of the Oracle string (notice the leading double quote):
 User generated image
and here's the HTML view of the string entered by the user through the text box (notice no quotes):
 User generated image
Not sure what I am doing wrong here, please help.

Thanks,

Jason
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Are you sure that the value on Oracle is stored without the " ?

Another suggestion: store the passwords encrypted in the database and when you query the database, pass the encrypted password and username and return true or false (if combination of username-pwd is correct)
Please try following

If String.Equals(txtPassword.Text.Trim(), Drawing.GetOracleString(0)) Then
Avatar of jchaplw
jchaplw

ASKER

Dhaest:  I did check the value in Oracle and it does not have any double quotes.  I will give your suggestion a try.

IJZ:  I tried your suggestion and I am getting an error:  GetOracleString is not a member of Drawing

  I am not familiar with the Drawing class so I will investigate it further to see what member(s) I need to use to get that to work.

thanks

 
sorry there is type

If String.Equals(txtPassword.Text.Trim(), dr.GetOracleString(0)) Then
Avatar of jchaplw

ASKER

Oh, duh, why didn't I see that?  

Ok, I tried

If String.Equals(txtPassword.Text.Trim(), dr.GetOracleString(0)) Then

but I am getting the same exact result with the double quote leading the string from Oracle.

Then try following too

If String.Equals(txtPassword.Text.Trim(), dr.GetOracleString(0).Trim("""")) Then

or

If String.Equals(txtPassword.Text.Trim(), dr.GetOracleString(0).Trim("""")Trim()) Then
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What is that decrypt function in your select?
Avatar of jchaplw

ASKER

IJZ:  I tried your suggestion but it is complaining that Trim is not a member of GetOracleString

Dhaest:  I have tried your suggestion and I am close but I keep getting this error:

Unable to cast object of type 'System.Decimal' to type 'Oracle.DataAccess.Client.OracleDataReader'.

Here's my new code below...I've tried dr.GetOracleString(0), dr(0) and dr.GetValue but all give me the same error.

 
Dim sqlStr As String = "select count(*) " & _
                     " from lw.lw_LMS_EMPLOYEES e " & _
                     " where e.securitycode = 'ADMIN' " & _
                     " and e.password = lw.lw_lms_password.encrypt( '" & txtPassword.Text & "') " & _
                     " and e.userid = '" & Me.txtUserID.Text & "'"

            Dim dr As OracleDataReader
            Dim dbCon As New DBAccess(Master.GetEnvironment)

            dr = dbCon.ExecuteScalar(sqlStr)

            If dr.HasRows Then
                dr.Read()
                If dr(0) <> 0 Then
                    Me.lblError.Text = "Success"
                Else
                    Me.lblError.Text = "Password does not match."
                End If
            Else
                Me.lblError.Text = "User ID " & txtUserID.Text & " was not found as an ADMIN user. Please try again."
            End If

Open in new window



CodeCruiser:  The decrypt and encrypt function is a custom Oracle function that we use to handle password encryptions.  I know the function works as expected since I tested the query in Oracle.
Avatar of jchaplw

ASKER

Not sure why the ExecuteScalar is not working, that is what is causing the error though.  I changed it back to ExecuteReader and it works now.  Guess I need to learn more about the difference between those two.

Thanks for your help!
Sorry, was driving to home...

Here the solution with executeScalar
Dim dbCon As New DBAccess(Master.GetEnvironment)

            dim dr as decimal
            dr = dbCon.ExecuteScalar(sqlStr)

            if dr(0) <> 0 Then
                    Me.lblError.Text = "Success"
            else
                    Me.lblError.Text = "Password does not match."
           end If

Open in new window