10 ASP Institute of the fifth day
Learning Objective: To learn the basic operation of a database (the record)
The database is nothing more than basic operations: query records, written records, delete records, modify records. Today, we are learning the record first.
To the establishment of a form:
<form Name="form1" method="post" action="example5.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="æäº¤">
<input Type="reset" name="Submit2" value="é‡ç½®">
</ Form>
Example5.asp form submitted to the following are example5.asp code:
<%
Set conn = server.createobject ( "adodb.connection")
Conn.open "driver = (microsoft access driver (*. mdb)); dbq =" & server.mappath ( "example3.mdb")
Name = request.form ( "name")
Tel = request.form ( "tel")
Message = request.form ( "message")
Exec = "insert into guestbook (name, tel, message) values ( '" + name +"',"+ tel +",'"+ message +"')"
Conn.execute exec
Conn.close
Set conn = nothing
Response.write "added success record!"
%>
Here I do not say that in front of two, three, I do not say that behind the front inside the exec said the implementation of the orders, add records comparison fan, we have to look at carefully. And insert into the table behind the name behind inside the brackets is the need to add fields, or fields do not have to add the content that is the default value can be omitted. Note that the variable must ACCESS inside and the name of correspondence, it will go wrong. Values behind the increase is transmitted over the variables. Exec is a string, "insert into guestbook (name, tel, message) values ( '" is the first, not embedded in ASP inside double quotes, so can be used' instead of double quotes, in double quotes inside connecting the two Variables with + or & Therefore, " '," also is a middle name of a folder that came form the variables, this variable can be in the outside plus two'', said the string, behind the tel figures Variable siege''outside so there is no need, we slowly analysis of this sentence, if the data came with the form name of the substitute variables for this statement (assuming name = "aaa", tel = 111, message = "bbb") : "insert into guestbook (name, tel, message) values ( 'aaa', 111, 'bbb')."
Next conn.execute exec is the implementation of the order, do not forget to open the final database close to the definition of components set to air, and so can return to the resources. In order to read the last simple, I have not closed, we can add forward:
Rs.close
Set rs = nothing
Conn.close
Set conn = nothing
Remember, the order can not be reversed!
We can to the database inside to see, read or use example4.asp see if it is more than a record of A?
Tags: ASP








0 Comments to “10 ASP Institute of the fifth day”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.