Solved

asp recordset compare field problem

Posted on 2009-03-31
11
443 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
UT-F and other ASP code. What is it for ? 3 31
Classic ASP - x-editable save to SQL 3 77
UTC (timezone) without using an API 16 39
SQL to update characters in table column 6 81
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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

943 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