Solved

asp recordset compare field problem

Posted on 2009-03-31
11
442 Views
Last Modified: 2012-05-06
Ok, I think I have gone into stupid mode after coding asp for god know how many years and asp.net for 2.5 yearsas I have a silly problem that I can not for the life of me see what is the issue...The code below checks to 2 seperate recordset fields to each other and writes out a word as to what action should taken. The problem is 'OK' is always returned even when the below values are being used in the RS's.

rsCommon("Real_name") = "" i.e. empty value
(rsUser("FIRSTNAME") & " " & rsUser("LASTNAME"))  = "Gordon Taylor"

I am sure it is a silly mistake that I have stupidly overlooked but for the life of me I do not understand why if rsCommon("Real_name") = "" (NULL/Empty) that it wont return "COPY" as this is the 1st check that is executed?
<%

Dim rsCommon__MMColParam2

rsCommon__MMColParam2 = ""

If (Request.QueryString("Username") <> "") Then 

  rsCommon__MMColParam2 = Request.QueryString("Username")

End If

%>

<%

Dim rsUser

Dim rsUser_cmd

Dim rsUser_numRows
 

Set rsUser_cmd = Server.CreateObject ("ADODB.Command")

rsUser_cmd.ActiveConnection = conn

rsUser_cmd.CommandText = "SELECT * FROM [USER] WHERE USERNAME = ?"

rsUser_cmd.Prepared = true

rsUser_cmd.Parameters.Append rsUser_cmd.CreateParameter("param1", 200, 1, 35, rsCommon__MMColParam2) ' adVarChar
 
 

Set rsUser = rsUser_cmd.Execute

rsUser_numRows = 0

%>

<%

Dim rsCommon__MMColParam

rsCommon__MMColParam = ""

If (Request.QueryString("Username") <> "") Then 

  rsCommon__MMColParam = Request.QueryString("Username")

End If

%>

<%

Dim rsCommon

Dim rsCommon_cmd

Dim rsCommon_numRows
 

Set rsCommon_cmd = Server.CreateObject ("ADODB.Command")

rsCommon_cmd.ActiveConnection = conn

rsCommon_cmd.CommandText = "SELECT * FROM dbo.tblAuthor WHERE Username = ?" 

rsCommon_cmd.Prepared = true

rsCommon_cmd.Parameters.Append rsCommon_cmd.CreateParameter("param1", 200, 1, 35, rsCommon__MMColParam) ' adVarChar
 

Set rsCommon = rsCommon_cmd.Execute

rsCommon_numRows = 0

%>

<%

If rsCommon("Real_name") = "" OR rsCommon("Real_name") <> (rsUser("FIRSTNAME") & " " & rsUser("LASTNAME")) Then 

		Response.write "COPY!" 

	else

		Response.write "OK"

	End If

Open in new window

0
Comment
Question by:clearchannel
  • 5
  • 5
11 Comments
 
LVL 29

Accepted Solution

by:
QPR earned 250 total points
Comment Utility
have you tried using trim() arounf the firstname and lastname values just in case?
when using asp and falling into these problems I always do a response.write of the values I want to compare just in case there is some unexpected data returned (or null)
0
 

Author Comment

by:clearchannel
Comment Utility
Trimming makes no difference, the if still doesn't execute correctly and BROKEN is returned.
It's more wierd than it being a space issue, it;s as though the if else isn't working correctly as COPY should be returned if there is no match, and there isn't.
0
 

Author Comment

by:clearchannel
Comment Utility
Due to random NULL value I am going to use
IsNull(rsCommon.Fields.Item("Real_name").Value)
0
 
LVL 29

Expert Comment

by:QPR
Comment Utility
broken?

Are we talking SQL Server?
Are real_name, firstname and lastname all the same datatypes?
I mean are they all varchars or all chars?
A char value may not equal a varchar value even if they look identical as char fields are padded to use up the unused space in the datalength.

example
field1 varchar(10)
field2 char(10)

would be
"smith"
"smith     "
respectively
0
 

Author Comment

by:clearchannel
Comment Utility
Error was due to NULL values in the sql table where I didn't expect them to be.
Like I said silly simple thing I overlooked but couldn't for the life of me see where I was mi-firing.
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 29

Expert Comment

by:QPR
Comment Utility
hmmm I think my first comment was to check the values returned in case you were getting unexpected values e.g. nulls

"when using asp and falling into these problems I always do a response.write of the values I want to compare just in case there is some unexpected data returned (or null)"
0
 

Author Comment

by:clearchannel
Comment Utility
You made a single comment about null values which to be honest your actual response was regarding TRIM and testing for padding round strings as is your 2nd response.
I also solved the solution myself and posted the code, let the post be deleted as it is totally irrelevant and no use to anyone. Just an oversight by myself to which I provided the solution!
0
 
LVL 29

Expert Comment

by:QPR
Comment Utility
"You made a single comment about null value"

How many comments about null values should I have made before you checked for null values?
0
 

Author Comment

by:clearchannel
Comment Utility
To be prefectly honest I skimmed your post and saw the part about TRIM and stopped reading as I had a few ideas of my own. I only noticed you'd actually said NULL in your comment after you brought it up in your objection and in which time I had already figured out what silly thing I had forgot to do and check for, and thus I posted a solution.
I have requested the deletion of this topic as it was my silly mistake through looking too hard. Keeping the topic on EE doesn't benefit anyone except you, even though you did not provide a concise solution.
0
 
LVL 29

Expert Comment

by:QPR
Comment Utility
I'm happy to leave this to the moderator.
I have no need of the points as I have expert status but I do like to see the EE process run it's proper course.
To my knowledge it is not best practice to ask a question, not read the replies properly and then claim to have solved the issue by finding the exact reason that was mentioned in the responses.
No matter how trivial or silly your oversight.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

6 Experts available now in Live!

Get 1:1 Help Now