Ten days to learn the fourth day of the ASP [Author: Anonymous Copy from: Site author Hits: 3719 Update Time: 2004-4-6 article entry: ywdong]
Learning Purpose: Master the connection and reading records of the Access database today have a bit boring, but it is very important. Here everyone don't need to know the specific operation of the order. The reason why many books outside is not suitable for entry is because of the introduction of too many theoretical knowledge, so that beginners foggy. Let's see the mountain, look at the two sentences: <% set conn = server.createObject ("adoDb.connection" conn.open "driver = {Microsoft Access Driver = {Microsoft Access Driver (* .mdb)}; DBQ =" & Server.mAppath ("EXAMPLE3. MDB ")%> The first sentence defines an ADODB database connection component. The second sentence is connected to the database, and everyone can modify the name of the database. Is not it simple? Let's take another three sentences: <% exec = "select * from guestbook" set = server.createObject ("adoDb.recordset") rs.open exec, conn, 1, 1%> These three sentences are added in front of two sentences Later, the first sentence: Set the command of the query database, after select, if you need to query, use *, from the back of the table, what is the previous establishment is a GustBook form? The second sentence: Define a recordset assembly, all search records are placed here, the third sentence is to open this recordset, and EXEC is the previously defined query command, and conn is the database connection component, which is the previously defined database connection components, back parameters " 1, 1, this is read, and then the modified record will set the parameters to 1, 3, and let's read the record.
<% do while not rs.eof%>
<% = RS ("Name")%> <% = rs ("tel")%> <% = rs ("message")%> <% = rs ("time")%> <% = rs.movenextLoop% >
In a table, we showed the four fields in the last created table with a 4 column, with the DO loop, NOT RS.EOF means that the condition is not to read the record set, RS.MOVENEXT means It is shown to be turned to a record, <% =%> is equal to <% response.write%> Used to insert an ASP code in the HTML code, mainly for display variables. It's better to come today, everyone can practice more, you can download my example first, debug it. Here is the result picture above the machine.
Ten days to learn the fifth day of the ASP [Author: Anonymous Copy from: Site author Hits: 3327 Update Time: 2004-4-6 article entry: ywdong]
Learning Purpose: Society of Basic Operation 1 (Write Record) 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:
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 ") "connecute execconn.closset conn = NothingResponse.write" recorded success! "%> I have two words in front of me Don't say it, I don't say three sentences later. I have said that the execution of the execution is the execution of the execution. If you have 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' "." Next Conn.execute is to execute this exec command, don't forget to close the open database, put The defined component is set to empty, so you can return resources. The last read is for simple, I don't turn it off, everyone can add: rs.closset rs = nothingconn.closset conn = Nothing Remember, the order can not be reversed! You can to the database inside to take a look, see if it is more or recorded with example4.asp a reading of ten days to learn ASP sixth day [? author: Anonymous Copy from: site author Hits: 3086 update time: 2004 -4-6 Article entry: ywdong]
Learning Purpose: Society of Basic Operations 2 (Query Record) In the fourth day, we have such a program: <% set conn = server.createObject ("adoDb.connection" conn.open "driver = {Microsoft Access Driver * .mdb)}; dbq = "& server.mappath (" eXample3.mdb ") exec =" select * from guestbook "set = server.createObject (" adodb.recordset ") RS.Open EXEC, CONN, 1, 1 %> We query all records, but we want to modify, when deleting records, it is impossible to be all records, all we have to learn to retrieve appropriate records. First look at a statement: a = "Zhang 3" b = 111 exec = "Select * from guestbook where name = '" a "' and tel =" bwhere back plus conditions, and is and is or or OR , I want to =, <=,> =, <,> all know. The meaning of this is to search NAME is Zhang San, and the phone is a record of 111. Another point is that if you want to search for a string, you can write this: WHERE INSTR (Name, a) is also a person in searching with A (Zhang 3) this string in Name. I here's a, b, is constant, everyone can let A, b is the variable submitted by the form, so you can do a search. Let's take a look at this code, understand: example6.asp: <% name = request.form ("name") Tel = Request.form ("tel") set conn = server.createObject ("AdoDb.Connection" conn .open "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("eXample3.mdb") exec = "SELECT * from guestbook where name = ' name "' and tel = " Telset RS = Server.createObject ("AdoDb.Recordset") rs.Open Exec, CONN, 1, 1%>
<% do while not rs.eof%>
<% = RS ("Name")%> <% = rs ("tel")%> <% = rs ("message")%> <% = rs ("time")%> <% = rs.movenextLoop% >
Today, I actually talked a WHER. Everyone went back to do the test, and I in INSTR (), see you tomorrow!
Ten days to learn the seventh day of the ASP [Author: Anonymous Copy from: Site author Hits: 2201 Update Time: 2004-4-6 article entry: ywdong] Learning Objective: To learn the basic operation of the database 3 (delete records) straight to the point, Everyone looks directly to the program. Exec = "delete * from guestbook where id =" & required.form ("ID") This sentence completes the operation of deleting records, but the lock record has been recorded for the unique representation ID, when we use the database in front to use the database The system gives us the primary key, the name is the number. Because it is the Chinese name is not very convenient, everyone can modify it to ID, if you do not modify it is exec = "delete * from guestbook where number =" & required.form ("id") below. Look at the full code: A form is passed to an ID file, then this ASP file deletes this ID.
Example7.asp: <% set conn = server.createObject ("adodb.connection" conn.open "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("eXample3.mdb") EXECH = "Delete * from guestbook where number =") conn.execute exec%> I added an example72.asp in the example, and Example4.asp is almost the same, that is, I added a ID field, everyone can First run this file to see all recorded IDs and want to delete records, and then review this file after deleting records. Wait until the last day, we will integrate all these things. Everyone will not need such a troublesome operation. Example72.asp: <% set conn = server.createObject ("adodb.connection") conn.open "Driver = {Microsoft Access Driver (* .mdb)}; dbq =" & Server.mappath ("eXample3.mdb") EXECH = "Select * from guestbook" set = server.createObject ("adoDb.recordset") rs.open exec, conn, 1, 1%>
<% do while not rs.eof%>
<% = rs ("Number)%> <% = RS (" Name ")%> <% = RS (" Tel ")%> <% = rs (" Message ")%> <% = rs (" Time ")%> <% rs.movenextLoop%>
Ten days to learn the ASP eighth day [Author: Anonymous Copy from: Site author Hits: 2085 Update Time: 2004-4-6 article entry: ywdong]
Learning Purpose: Society of Basic Operations 4 (Modify Record) First View Code: <% SET CONN = Server.createObject ("AdoDb.Connection" Conn.open "Driver = {Microsoft Access Driver (* .mdb)}; DBQ = "& server.mappath (" test.mdb ") // This is not a previous database, on the AA, BB field exec =" select * from test where id = "& recommended.QueryString (" ID ") SET RS = Server.createObject ("AdoDb.Recordset") rs.open exec, conn%> <% rs.closset rs = nothingconn.closset conn = Nothing%> Everyone should analyze this code without any problem, this code role It is the ID that accepts the previous page and then display this record. The text box is also the place where the input is also displayed. If you need to modify it, you can press the commit; if you do not need to modify it, you can press the Submit button directly. There is still a thing before, that is, hidden form element: hidden element, the value of the value is not entered, which will be submitted with the form, used to transfer the variable. Below is the code: <% set conn = server.createObject ("adoDb.connection" conn.open "Driver = {Microsoft Access Driver = {Microsoft Access Driver (* .mdb)}; DBQ =" & Server.mappath ("TEST. MDB ") EXEC =" Select * from test where id = "& required.form (" id ") set = server.createObject (" adoDb.recordset ") RS.Open EXEC, CONN, 1,3RS (" aa ") = Request.form ("AA") = Request.form ("BB") rs.Updaters.closset RS = NothingConn.Closset Conn = Nothing%> Here, RS.Open EXEC, CONN, 1 The parameters behind 3 are 1, 3, which I used to mention it, and the modification record should be used 1, 3. In fact, modifying the record is easy to understand, the record set is RS, RS ("AA") is the current record of the AA field, allowing it to wait for the new data Request.form ("AA") of course, but finally Forgot to save, it is rs.update! Speaking of this, recorded search, reading, modification, and inserting, through this most basic thing, you can make a complex thing, large database: news system, message book is a point. The code in today's example is combined with the previous database, everyone down will go back to debug analysis. (The example72.asp in RAR is for everyone to query the record ID and the recording of the recording after the changes)
ASP ten days of the ninth day learn [Author: Anonymous Copy from: Site author Hits: 1944 Update Time: 2004-4-6 article entry: ywdong] Learning Objective: basic SESSION component summary response, request components. First, any program with a member system will use to detect whether the user has already logged in this step. This uses the session component, let's take a look at a code. <% session ("islogin") = "YES"%> This sentence means defining a islogin string variable in session, the value is "YES", which can be assigned directly, and no statement is required. Is not it simple? If we do administrators to log in, the first is that the administrator if the admin IF is the session ("isadmin") = yes "else session (" isadmin ") =" no "End if The top of the page plus <% if not session ("isaAadmin") = "Yes" theresponse.redirect "login.htm"%> This general user can not open this page. Explain that response.redirect, it is turning meant "Login.htm" behind, is the turn to the file. This is not available to the manager that cannot be seen later. He summarizes the response.write (), response.Redirect (), response.redirect () The role of writing strings and steering reluest is basically request.form (), request.QueryString () is accepting post, get method, the information passed by the GET method is here today, and finally my demonstration is a landing system. You can study In the case, it is basically that the above knowledge points are relatively simple.
The tenth day of the ASP ten days to learn [Author: Anonymous Copy from: Site author Hits: 2158 Update Time: 2004-4-6 article entry: ywdong]
Learning Purpose: Summary Technology, Summary Today I have learned a little difficult to page this ASP. After all, when we have N records, we cannot display all records inside a page. <% exec = "select * from test" set = server.createObject ("adoDb.recordset") rs.Open Exec, conn, 1,1rs.pageSize = 3PageCount = rs.PageCount Page = int (Request.QueryString (" Page ")) = 1if request.queryString (" page ") =" "" "= 1rs.absolute = Page%> rs.pageSize Settings the number of records displayed in a page, PageCount is our own One variable defined, rs.pagecount is the number of records, Page is also a variable we defined by our own, and the next page can be set to list.asp? Page = <% = Page 1%>, next page The link can be set to list.asp? Page = <% = page-1%> So when you press the link, call the page yourself, Page variable 1 or -1, finally let RS.Absolute (current The page is available for the Page page. if Request.QueryString ("Page") = "" "" The role of this sentence is that when we open list.asp, it does not follow the PAGE variable, automatically set to Page = 1, prevent errors, and when we .... THEN ... End IF can be omitted when it is placed. Is it not difficult? Here is a special case: if page = 1 and not page = pagecount, this time does not have a previous page, but there is next page elseif page = PageCount and not page = 1, this time no next page, but there is a previous one Page Elseif Page <1, this time no record elseif page> PageCount Then, this time no record elseif page = 1 and page = pagecount, this time no previous page, no next page ELSE, this time there is a previous page And there is also next page. Let's take a look at 1 to N pages, and each number will appear after the number of the code on the representative page, very common. <% for i = 1 to PageCount%> <% = i%> <% next%> for .... next is the cycle starts from i = 1, cycles 1 to PageCount. Finally, my instance contains the simplest ASP program, but the functionality is the essence of the ASP, and each ASP large program contains it. Add.htm Add Record page add.asp Add Record Operation Conn.asp Database Link DEL.ASP Delete Record Operation MODIFY.ASP Modify Record Page MODIFYSAVE.ASP Modify Record Operation List.asp This is the core of this program, and implements records through this page Add, modify, delete.