I. Common mistakes made by new users
I saw many posts in the Forum
Code There is a common basic error and the field type is incorrect.
Program It is closely connected to the database. single quotation marks are used for text or time fields of the database.
For example, the following statement is modified:
Conn.exe cute "Update counts set counts = '" & counts & "'where num =" & num & "and atime ='" & now ()&"'"
The left side of the equal sign is the field name, the right side is the variable name passed in the value, and the counts field is a text type. Therefore, a single quotation mark must be added before and after the equal sign is written, and both the write and query operations are the same, in the following query statement, the num field is a number type, so there is no single quotation mark before and after it, and the atime field is a time type. Therefore, single quotation marks must be added before and after it.
The most important thing is the ID query. The ID field is unique and numeric. It is obvious that there are no single quotation marks before and after the ID number is queried.
Conn.exe cute "Update counts set counts = '" & counts & "'where id ='" & ID & "'"' incorrect syntax
Conn.exe cute "Update counts set counts = '" & counts & "'where id =" & id'
2. Access Database Connection
There are usually two ways to connect to a database. A newbie basically doesn't know which method to use, or under what circumstances, or how the two work.
① Directly connect to database files
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath ("database/yanhang. mdb ")
② Connect to database files through data sources
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath ("database/yanhang. mdb ")
Which of the two is better? Of course, it is the second one, because the first one is to directly read the database from the client browser, so the security is much worse. The second is to connect to the database through the data source, it is connected by a server data source tool and has nothing to do with the client, so the database will not be exposed to the client, and the security factor is much higher.
Application of the corresponding program of the Access Database: ① directly connect to the database file
Conn. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & server. mappath ("database/yanhang. mdb ")
To add a statement for this database connection method:
Set rs = server. Createobject ("ADODB. recordset") '(correct syntax)
Rs. Open "select * From dndj", Conn, 1, 3
Rs. addnew
RS ("bh") = BH
RS ("BM") = BM
RS ("XM") = XM
RS ("xsq") = xsq
Rs. Update
Rs. Close
Set rs = nothing
Set rs = server. Createobject ("ADODB. recordset") '(incorrect syntax)
SQL = "insert into dndj (BH, BM, XM, xsq) values ('bh ', 'bm', 'xm ', 'xsq ')"
Rs. Open SQL, Conn, 1, 3
Application of the corresponding program of the Access Database: ② connect to the database file through the data source
Conn. Open "provider = Microsoft. Jet. oledb.4.0; Data Source =" & server. mappath ("database/yanhang. mdb ")
To add a statement for this database connection method:
Conn.exe cute "insert into dndj (BH, BM, XM, xsq) values ('" & BH & "', '" & BM &"', '"& XM &"', '"& xsq &"') "'(correct syntax)
Set rs = server. Createobject ("ADODB. recordset") '(incorrect syntax)
SQL = "insert into dndj (BH, BM, XM, xsq) values ('bh ', 'bm', 'xm ', 'xsq ')"
Rs. Open SQL, Conn, 1, 3
Iii. Application of Double quotation marks
Usually we write a super connection like this <a href = "ABC. asp? Id = <% = RS ("ID") %> "> super connection </a>
But what if I compile this super connection into asp?
Response. Write "<a href =" "ABC. asp? Id = "& RS (" ID ") &" "> super connection </a>" '(correct syntax)
Response. Write "<a href = 'abc. asp? Id = "& RS (" ID ") &" '> super connection </a> "' (correct syntax)
Response. Write "<a href = ABC. asp? Id = "& RS (" ID ") &"> super connection </a> "'(correct syntax)
Response. Write "<a href =" ABC. asp? Id = <% = RS ("ID") %> "> super connection </a>" '(incorrect syntax)
Response. Write "<a href =" ABC. asp? Id = "& RS (" ID ") &"> super connection </a> "'(incorrect syntax)
Form compilation into ASP <input type = "text" name = "ID" value = "<% RS (" ID ") %>"/>
Response. write "<input type =" "text" "name =" "ID" "value =" & RS ("ID ") & "/>" '(correct syntax) Note: There are three double quotes
Response. Write "<input type = 'text' name = 'id' value = '" & RS ("ID") & "'/>" '(correct syntax)
Response. Write "<input type = text name = ID value =" & RS ("ID") & "/>" '(correct syntax)
Response. Write "<input type =" text "name =" ID "value =" <% = RS ("ID") %> "/>" '(incorrect syntax)
Response. Write "<input type =" text "name =" ID "value =" "& RS (" ID ") &" "/>" '(incorrect syntax)