Use ASP to insert the form data into the two common methods of database:
1. Use the SQL statement directly
Advantages: Fast speed, not consuming resources
Disadvantages: The content of the field that cannot be passed too long, the field is not easy to discharge.
It is recommended that experienced programmers are preferred.
Specific operation:
Assume that there are the following fields in the form: username, password, sex, Age
Correspondingly, there are Username, Password, Sex, Age in the program.
There are Username, Password, Sex, Age field in User. Other Age is the number field.
The Connection object has been established and the link is opened.
SQL = Insertinto [User] (Username, Password, Sex, Age) Value (& Username &, & Password &, & Sex & Age &)
conn.execute (SQL)
It is worth noting that if the username contains a single quotation number, there will be an error. The solution is to process the string function first. My commonly used method is to create a SQLENCODE function.
FunctionSQLENCODE (STR)
sqlencode = & replace (str ,,,) &
endfunction
In this way, the SQL name above can be simplified to SQL = Insertinto [username, password, sex, Age) X) &, & Age &)
Pay attention to the order of the field name in the previous list and the value of the values behind the value of the previous list. Pay attention to the corresponding relationship. If the value is empty, you can not fill in it, but if you represent the separation, the number cannot be omitted.
When the additional field is the string field, pay attention to add the number to the content before and after.
In addition, the brackets above the table name are because the User table may be a system table, and the upper brackets will not conflict with the system. Adding to the table name is also a good habit of ensuring the compatibility of the code.
2. Use RecordSet object
Advantages: code is easy to read, remove wrong
Disadvantages: consumed system resources
Recommended novice use
The environment is as follows as follows:
setrs = Server.createobejct (Adodb.oldSet)
sql = select*from [user]
RS.OPENSQL, CONN, 2,3
RS.Addnew Note that this line adds a new record. If it is missed, the previous record will be changed.
rs (username) = username
rs (password) = password
rs (sex) = sex
RS (Age) = Age
RS.UPDATE will be updated into the database
RS.Close's fastest closure of the RECORDSET object is a good habit
SetRS = Nothing is also a good habit to release unused objects
The above methods are more commonly used. Of course, you can also use a storage process. This article is no longer explained. You can search for related tutorials on this site!