ASP 101 - Active Server Pages 101 - Web03
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
The Top 10 ASP Links @
What is and Why Do I Need It?
An Overview of ASP.NET

Fix for IIS security bug
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

SQL Preparation Functions by Lewis Moten
These routines are used to allow you to prepare various data types for SQL
statements.  Some of them determine if a valid data type is being submitted.
If it is not valid, "NULL" would be returned to submit into a database.
The most common routine is "SQLPrep_s" (standing for SQL Prepare String).
The first variable that you would pass to this routine is the string you are
going to prepare.  The second is the length.  The longest text/varchar field
can be 255 characters.  If you have a memo/text field, then there is no
maximum length.  You can get around this by entering a number less then 0.
Text/VarChar of 255 characters or less:
SQL = "INSERT INTO MyTable(Author) VALUES(" & SQLPrep_s("Lewis Moten", 255)
& ")"
Text/VarChar 50 characters in length or less:
SQL = "INSERT INTO MyTable(Email) VALUES(" & SQLPrep_s("",
50) & ")"
SQL = "INSERT INTO MyTable(Page1) VALUES(" & SQLPrep_s(LargeParagraph, -1) &
Booleans are Yes/No, True/False fields.  A Boolean field can not be null.
So if the data type is wrong, a default data type has to be passed.  In the
following statement, if the Request field is not a valid answer (TRUE or
FALSE) then False is assigned.  The value returned for TRUE my change (-1 or
1) depending on the version and type of database that you are using.  The
notes in that function will explain which ones to use.
SQL = "INSERT INTO MyTable(21OrOlder) Values(" &
SQLPrep_b(Request("21OrOlder"), False) & ")"
The next statements only require the value itself.  Null is returned if the
value is not of the correct type.
SQL = "INSERT INTO MyTable(LuckyNumber) VALUES(" &
SQLPrep_n(Request("LuckyNumber")) & ")"
SQL = "INSERT INTO MyTable(PostDate) VALUES(" & SQLPrep_d(Now()) & ")"
SQL = "INSERT INTO MyTable(GetPaid) VALUES(" & SQLPrep_c("$1234.56") & ")"
View Download
Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers