Recommended: Common codes for ASP programming Common codes for ASP programming -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Asp to write records:
Learning purpose: Learn the basic operations of the database - write records
The basic operations of the database are nothing more than: querying records, writing records, deleting records, and modifying records.
Today we will learn to write records first. Create a form first: (Save the following article as 5.htm)
<form name=form1 method=post action=exa5.asp>
name <input type=text name=name><br>
tel <input type=text name=tel><br>
message <input type=text name=message value=><br>
<input type=submit name=Submit value=submit>
<input type=reset name=Submit2 value=Reset>
</form>
Submit the form to exa5.asp, and the following is the code for exa5.asp: (Save the following code as 5.asp)
<%
set conn=server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)};dbq=&server.mappath(data/guestbook.mdb)
name=request.form(name)
tel=request.form(tel)
message=request.form(message)
exec=insert into guest(name,tel,message)values('+name+',+tel+,'+message+')
conn.execute exec
conn.close
set conn=nothing
response.write record added successfully!
%>
I won’t say the first two sentences here, and I won’t say the last three sentences. I said that the exec is the commands executed, and the records are added are quite complicated, so everyone should read them carefully.
The name of the table is added after insert into, and the parentheses afterwards are fields that need to be added. The content of the field is the default value and can be omitted. Note that the variables here must correspond to the field names in ACCESS, otherwise an error will occur. The values are added to the transmitted variable. exec is a string, insert into guest(name,tel,message)values(' is the first paragraph, and double quotes cannot be embedded in ASP, so you can use ' instead of double quotes, put them in double quotes, and connect two variables with + or & so', another paragraph, and a name is inserted in the middle is the variable passed from the form, so you can add two '' outside of this variable, indicating that it is a string, and the tel behind is a numeric variable, so there is no need to be surrounded outside. Everyone analyzes this sentence slowly. If the data sent from the form is used instead of the variable name, the sentence is (assuming that name=aaa,tel=111,message=bb): insert into guest(name,tel,message)values('aaa',111,'bbb').
The next conn.execute is to execute this exec command. Finally, don’t forget to close the open database and set the defined component to empty, so that the resource can be returned.
The following statements are used to close the database code:
rs.close
set rs=nothing
conn.close
set conn=nothing
Remember, the order cannot be reversed! You can go to the database to take a look, or use duqu.asp to read to see if there are too many records? The following is a diagram of me reading the database using the files from the previous section:
Share: asp FSO read and write files this file implementation code Asp has passed for a while, let me talk about using asp fso to implement file read and write operations. Friends who need to learn can refer to it. 1.AtEndOfStream This property indicates whether the end of the entire text file has been reached. Its value is TRUE or FALSE 2.CreateTextFile is used to create a new text file 3. Parameters saucer in OpenTextFile() method (See Greeting)