CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Validate Against Lookup Table

Print topic Send  topic

Author Message
hfshultz

Posts: 17
Posted: 05/18/2004, 12:47 PM

I'm looking for a way to validate an edit box against a field in a table. The reason I'm not using a listbox is that this is a discount code field. I want it to check to see if the form field matches a record in the table and fail validation if it does not.

I am using SQL 2000 with ASP.

Thanks,
Frank
View profile  Send private message
peterr


Posts: 5971
Posted: 05/19/2004, 12:18 AM

Take a look at the validation examples in the docs:
http://docs.codecharge.com/studio/html/ProgrammingTechn...Validation.html
http://docs.codecharge.com/studio/html/ProgrammingTechn...Validation.html

You can use the CCDLookup function to retrieve the database value and compare it to the field value.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
hfshultz

Posts: 17
Posted: 05/19/2004, 12:12 PM

OK, CCDLookup will definitely work, but how do I compare the return value if there is none? IE: I want the error to display if the value is not found in the lookup. What value does CCDLookup return when the WHEN statement finds no records? Below is what I tried, but it doesn't do anything when I place it in the code in the On Validate event:

If CCDLookup("CostID", "Costs", "Code='"&Clients.RegCode.value&"'", DBconfdata) = Null Then
Clients.Errors.addError("This is not a valid Registration Code. Either clear the code or enter a valid code to continue.")
End if

Thanks,
Frank
View profile  Send private message
peterr


Posts: 5971
Posted: 05/20/2004, 1:09 AM

You should check for whatever the ASP returns after running such query, therefore the question is how ASP works and what does it return. I actually also don't know the answer but a simple test will show:

If CCDLookup("CostID", "Costs", "Code='"&Clients.RegCode.value&"'", DBconfdata) = Null Then Print "NULL;"
If CCDLookup("CostID", "Costs", "Code='"&Clients.RegCode.value&"'", DBconfdata) = "" Then Print "NOTHING;"
If IsEmpty(CCDLookup("CostID", "Costs", "Code='"&Clients.RegCode.value&"'", DBconfdata)) Then Print "EMPTY;"
If CCDLookup("CostID", "Costs", "Code='"&Clients.RegCode.value&"'", DBconfdata) = 0 Then Print "ZERO;"
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
Tony Do
Posted: 05/20/2004, 4:50 PM

I would trim the return value and then test to see if it length = 0, because
it some time it return a blank value

<Code>
Dim returnvalue
returnvalue = CCDLookup("CostID", "Costs",
"Code='"&Clients.RegCode.value&"'", DBconfdata)
returnvalue = trim(returnvalue)
If (len(returnvalue) = 0 ) Or (returnvalue = empty) Then
add the error message
End If
</Code>

If the CostID is integer field then you need to cast the return to type
integer or long,

ie
<Code>
Dim returnvalue
returnvalue = clng(CCDLookup("CostID", "Costs",
"Code='"&Clients.RegCode.value&"'", DBconfdata))
If (returnvalue = 0) or (returnvalue = empty) Then
add the error message
End If
</Code>
hfshultz

Posts: 17
Posted: 05/25/2004, 5:32 AM

Awesome, your code worked, Tony Do.

Thanks!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.