Strengthen ASP learning 2

xiaoxiao2021-03-06  104

The basic operation of the database is nothing more than: query record, write record, delete record, modify the record. Today we learn to write records.

Set up a form first:

Name

Tel

Message

The form is submitted to Example5.asp, below is the code of Example5.asp:

<%

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 "Record Add success!"

%>

Here I don't say two words, I don't say it, I don't say it. I have said that the execution of the execution is the execution of the execution. If you add a record, everyone should look carefully. INSERT INTO is added to the name of the table, and the back parentheses is a field that needs to be added, and the content that does not have to be added or the field is the default value. Note that the variables here must correspond to the field name inside Access, otherwise it will be wrong. The VALUES is added to the transmitted variable. EXEC is a string, "INSERT INTO GUESTBOOK (Name, Tel, Message) Values ​​is the first paragraph, can not be embedded in the ASP, so you can use 'instead of double quotes, put it in double quotes, connect two The variable is or "" ', "is another, the middle clip has a Name is the variable from the form, so that you can add two' 'outside this variable, indicating that the string, the back tel is Digital variables so don't need to be surrounded by '', everyone slowly analyzes this sentence, if the data from the form is replaced by the variable name (assuming name = "aaa", tel = 111, message = "BBB "):" Insert Into GuestBook (Name, Tel, Message) Values ​​('AAA', 111, 'BBB') ". The next conn.execute is the execution of this exec command, don't forget to open it.

The database is closed, defined

The component is set to empty, so that the resource can be returned. The last reading is simple, I am not closed, everyone can add:

Rs.close

SET RS = Nothing

Conn.close

Set conn = Nothing

Remember, the order can't be reversed!

Everyone can go

Take a look inside the database, or read it with example4.asp to see if it is more recorded?

转载请注明原文地址:https://www.9cbs.com/read-96811.html

New Post(0)