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

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
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 @ Microsoft.com
What is Adovbs.inc and Why Do I Need It?
An Overview of ASP.NET

QUICK TIP:
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("Lewis@Moten.com",
50) & ")"
Memo/Text
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.
Number:
SQL = "INSERT INTO MyTable(LuckyNumber) VALUES(" &
SQLPrep_n(Request("LuckyNumber")) & ")"
Date:
SQL = "INSERT INTO MyTable(PostDate) VALUES(" & SQLPrep_d(Now()) & ")"
Currency:
SQL = "INSERT INTO MyTable(GetPaid) VALUES(" & SQLPrep_c("$1234.56") & ")"
View Download
Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

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