Link to home
Start Free TrialLog in
Avatar of clearchannel
clearchannel

asked on

asp recordset compare field problem

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

ASKER CERTIFIED SOLUTION
Avatar of QPR
QPR
Flag of New Zealand 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
Avatar of clearchannel
clearchannel

ASKER

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.
Due to random NULL value I am going to use
IsNull(rsCommon.Fields.Item("Real_name").Value)
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
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.
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)"
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!
"You made a single comment about null value"

How many comments about null values should I have made before you checked for null values?
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.
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.