Several common mistakes made by ASP beginners

Source: Internet
Author: User

1. Enable record set again before it is disabled:
------------------------------------
SQL = "select * from test"
Rs. Open SQL, Conn, 1, 1
If not Rs. EOF then
Dim myname
Myname = RS ("name ")
End if
SQL = "select * From mybook"
Rs. Open SQL, Conn, 1, 1
-------------------------------------
Solution: Close Rs. close before the second Rs. Open.
Or
Set RS1 = server. Createobject
Rs1.open SQL, Conn, 1, 1

2. Use the SQL keyword for the table name or field name
-------------------------------------
SQL = "select * from user"
Rs. Open SQL, Conn, 1, 1
-------------------------------------
User is the SQL keyword
Solution: change
SQL = "select * from [user]"

3. Use the locking method for update.
-------------------------------------
SQL = "select * from [user]"
Rs. Open SQL, Conn, 1, 1
Rs. addnew
Or
RS ("username") = "AA"
Rs. Update
-------------------------------------
The current record set is opened in read-only mode.
Solution:
Change
Rs. Open SQL, Conn, 1, 3

4. The comparison field values used in the query statement do not match the field type
-----------------------------------------
SQL = "select * from [user] Where id =" & myid &""
Rs. Open SQL, Conn, 1, 1
-----------------------------------------
Assume that the table is designed with the ID as a number, so there are some errors.
Solution:
SQL = "select * from [user] Where id =" & myid

5. An error occurred while checking the variable value.
-----------------------------------------
SQL = "select * from [user] Where id =" & myid
Rs. Open SQL, Conn, 1, 1
-----------------------------------------
Assume that the value of the myid variable is null, then the SQL statement becomes
SQL = "select * from [user] Where id ="
Solution:
Add
If isnull (myid) then error prompt

6. An error occurred while checking the variable value type.
-----------------------------------------
SQL = "select * from [user] Where id =" & myid
Rs. Open SQL, Conn, 1, 1
-----------------------------------------
Assume that the ID is numeric, and the value of myid is not null but a character. For example, myid is "AA"
Then SQL will become
SQL = "select * from [user] Where id = AA"
Solution:
Add
If isnumeric (myid) = false then error prompt

This can also effectively prevent SQL injection attacks.

7. data cannot be updated because of the NTFS permission in the directory where the database files are located. Database or object is read-only "error.
Note:
Wi
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.