[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-05-06
11
Medium Priority
?
326 Views
Last Modified: 2012-06-21
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?
 VB.net code string comparison
Using the debugger tool, here's the HTML view of the Oracle string (notice the leading double quote):
 Oracle string
and here's the HTML view of the string entered by the user through the text box (notice no quotes):
 User Entered string
Not sure what I am doing wrong here, please help.

Thanks,

Jason
0
Comment
Question by:jchaplw
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 35706322
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)
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35706347
Please try following

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

Author Comment

by:jchaplw
ID: 35706423
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

 
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35706428
sorry there is type

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

Author Comment

by:jchaplw
ID: 35706470
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.

0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35706553
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
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 35706583
I still remain with my first post:

Change your sql-string that you search for the user and password and use the
executeScalar (with the select like: select count(*) which will tell how many rows are found and valid)
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35706707
What is that decrypt function in your select?
0
 

Author Comment

by:jchaplw
ID: 35706795
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.
0
 

Author Comment

by:jchaplw
ID: 35707033
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!
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 35707779
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

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

872 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