Use database statements
1.select statement: command the database engine to return information from the database as a set of records.
2.insertinto statement: Add one or more records to a table.
3. Update statement: Create an update query to change the field values in a specified table based on a specific criteria.
4.delete statement: Create a delete query to clear the record from the from clause and to one or more tables that match the where clause.
5.execute statement: used to activate procedure (process)
Use Asp to make your own address book and practice your skills...
1. Create a database:
Use microsoftaccess to create an empty database named data.mdb and create a new table using the designer. Enter the following fields:
Field name data type description other
id Automatic numbering data identification field size: long integer new value: incremental index: Yes (no duplicates)
username text name default value
usermail text e-mail default value
view number view number field size: long integer default value: 0 index: none
period time date added to time default value
Save it as a data.mdb file. For the sake of explanation, I just made a relatively simple library.
2. Connect to the database
Square *1:
setconn=server.createobject("adodb.connection"
conn.open"driver={microsoftaccessdriver(*.mdb)};dbq="&server.mappath("data.mdb"
Square *2:
setconn=server.createobject("adodb.connection"
conn.open"provider=microsoft.jet.oledb.4.0;datasource="&server.mappath("data.mdb":'(
Note: In a page, you only need to connect once. After using the database, you must close the connection in time.
conn.close
setconn=nothing
3. Add new records to the database
setconn=server.createobject("adodb.connection":'(
conn.open"driver={microsoftaccessdriver(*.mdb)};dbq="&server.mappath("data.mdb":'(
username="State changes in the wind"
usermail="[email protected]"
instance=now()
sql="insertintodata(username,usermail,indata)values('"&username&"','"&usermail&"','"&indate&"')"
conn.execute(sql)
conn.close
setconn=nothing
Description: Establish a database connection; get the name and e-mail string through the form, and now() to get the current time and date; use the insertinto statement to add a new record; conn.execute to execute; finally close.
4. Select records in the database
1. Select the fields of all records (sorted in reverse order of records): sql="select*fromdataorderbyiddesc"