Solved

asp recordset compare field problem

Posted on 2009-03-31
11
445 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
ID: 24027248
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
ID: 24027281
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
ID: 24027313
Due to random NULL value I am going to use
IsNull(rsCommon.Fields.Item("Real_name").Value)
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 29

Expert Comment

by:QPR
ID: 24027317
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
ID: 24027340
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
 
LVL 29

Expert Comment

by:QPR
ID: 24027380
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
ID: 24027405
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
ID: 24027422
"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
ID: 24027483
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
ID: 24027532
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…

765 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