473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Validating in asp with access

It's good practice to validate input, not only where it should be coming
from, but from anywhere it's possible to change or add input for a
"client".
If all user input is transfered using "post" you can be pretty tough on
querystrings, if you use them at all.
But user input could have a name like Mc'Donald, and we would not like
quotes (wether single or double) in input to a database or an asp
script. Though I beleive more dangerous in SQL server there should be
(?) a danger with access as well. (The infamous SQL injection)
Anyone with some "input" in this matter?

Escape caracters? Haven't found any.
Changing the caracter "scriptwise"? Maybe

Mats
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
3 4960
Mats wrote:
It's good practice to validate input, not only where it should be
coming from, but from anywhere it's possible to change or add input
for a "client".
If all user input is transfered using "post" you can be pretty tough
on querystrings, if you use them at all.
But user input could have a name like Mc'Donald, and we would not like
quotes (wether single or double) in input to a database or an asp
script. Though I beleive more dangerous in SQL server there should be
(?) a danger with access as well. (The infamous SQL injection)
Anyone with some "input" in this matter?

Escape caracters? Haven't found any.
Changing the caracter "scriptwise"? Maybe

Mats

You double characters that need to be escaped:

sName = "O'Donald"
sName = Replace(sName, "'", "''")

The sName variable will now contain "O''Donald" (two apostrophes). When Jet
parses the query containing this string, it will interpret the two
consecutive apostrophes as a single quote.

This is how it is done in all forms of VB. If you need to create a string
containing a literal double quote, you do it by escaping the double quote:

sString = "9"" wrench"

It is also the way it is done in T-SQL when you get around to using SQL
Server.

Bob Barrows

Jul 19 '05 #2
Thanks Bob.
Ok - I should have remembered the four dubbleqoutes you ned in order to
escape quotes in asp.
I'm surprised that something so important and problematic is hardly
discussed at all.
Could you direct me and others to a source of information in this
matter?
Mats
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3
Mats wrote:
Thanks Bob.
Ok - I should have remembered the four dubbleqoutes you ned in order
to escape quotes in asp.
I'm surprised that something so important and problematic is hardly
discussed at all.
Could you direct me and others to a source of information in this
matter?
Mats

Most books on data access cover this. Bill Vaughn's "ADO Examples and Best
Practices" is a good one, despite being geared more to VB than ASP. Here's
something I posted a couple weeks ago that a couple people found helpful:

Here are the rules for delimiting data in dynamic sql strings, particularly
in the WHERE clause:
To decide whether or not to delimit the data, look at the datatype of the
FIELD BEING COMPARED TO - NOT THE DATA.

1. If it's a numeric field, you must supply it with numeric data, which
means you MUST NOT delimit the data by putting quotes around it.

2. If it's a character/text field, then you must supply string data by
delimiting the data either with single or double quotes. If the data
contains literal quotes, you must escape them by doubling them. This means
that if you use single quotes (apostrophes) for your string delimiters, and
the data contains an apostrophe, then you must replace the apostrophe with
two apostrophes, like this:
Update tbl set textfield = 'O''Malley'
In Access, you can use double quotes for your delimiters, so this will work
as well:
Update tbl set textfield = "O'Malley"
Note: you don't have to escape the apostrophe in O'Malley when you use
double quotes as the delimiter. However, you will need to escape the double
quotes when assigning this statement to a variable:
sSQL = "Update tbl set textfield = ""O'Malley"""
So most people will use the single quotes and escape the apostrophe:
sName = "O'Malley"
sSQL = "Update tbl set textfield = '" & Replace(sName,"'","''") & "'"
response.write sSQL

3. If it's a date/Time field, then the delimiters depend on the type of
database. Since you are using Access, then you must delimit the data with
hash marks (#). Additionally, you must supply the data in US format
(m/d/yyyy) or in ISO (yyyy-mm-dd), with the latter being the more
recommended.

4.Lastly, if you are using LIKE, you need to be aware that you must use %
and _ as the wildcards, not * and ?. This is true no matter what database
you are using

And then, when you think you have it right and it still does not work,
response.write it to see the result of your concatenation. If you've done it
correctly, you will have a statement that you can copy and paste from the
browser window into the SQL View of an Access Query Builder and run without
modification (unless you need to replace the wildcards with the Jet
wildcards).

This all seems rather difficult, doesn't it? Add to this the fact that a
dynamic sql query will not perform as well as a saved query/stored
procedure, and you have two strikes against it. Add the lack of security due
to leaving yourself open to a SQL Injection attack and you have three
strikes.

Let me show you how easy this can be using a saved parameter query. let's go
back to your statement and parameterize it* :

UPDATE tblListingspriceChanges SET NewPrice = [P1],
ChangeDate = [P2], [Name]=[P3], Original_Price=[P4]
WHERE PriceChangeID = [P5]

Do you notice ANY delimiters in the above sql statement? :-)
Test this statement in the Access Query Builder by running it: you will be
prompted to supply values for each of the parameters. Supply some values and
make sure it works as intended. When you've finished debugging it, save it
as qUpdPriceChange. Notice that you've created and debugged your query in
the environment where debugging and testing of queries should be done: in
the database environment.

Now to run it in ASP:
'create and open a connection object, cn, populate and
'validate your data variables, then:
cn.qUpdPriceChange NewPrice, ChangeDate, Name, _
Original_Price, PriceChangeI

If you are running a query that returns records, you can still use this
syntax, by supplying a recordset variable as an extra argument:

set rs = server.createobject("adodb.recordset")
cn.QueryName parm1,...parmN, rs
HTH,
Bob Barrows
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Brian Kedersha | last post by:
I found code for validating XML documents with the XML Schema cashed for rapid access. Example 3: Validating with XMLSchemaCache. ...
5
by: Steve | last post by:
I am currently trying to validate data in an access database. I need to verify that columns containing date information are in the format ddmmyyyy and columns containg time information are in the...
0
by: Elias Farah | last post by:
G'day People, I am wondering what is the general concensus about the best way of validating URLs stored in a ms-access table. I can't figure out any VB methods, however I have come across some...
6
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed...
0
by: Joe | last post by:
Hi For a while now I have been finding postings of problems with the validating event not firing on controls properly. I too had this problem. The event would fire when clicking on another...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
3
by: TheSteph | last post by:
Hi Experts ! I have a Winform Program in C# / .NET 2.0 I would like to ensure that a value in a TextBox is a valid Int32 when user get out of it (TextBox loose focus)
2
by: lrheeza | last post by:
Hello everyone, I am a newbie at MS Access and I need help!!! I am importing an excel file using Import functionality in MS Access, all the fields are required but there are instances in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.