Solved

asp recordset compare field problem

Posted on 2009-03-31
11
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

729 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