Abstract: This article demonstrates the function of using access query to construct a stored procedure similar to MSSQL, and insert data in ASP to display data.
Directory:
1. Create a table in the access query, named TT
2. Create a query in the access query with the following content :...
3. Use tt_insertparm in ASP to add 10 records to table TT
3.1 construct the asp ado connection function, fcreatecnn and fclosecnn
3.2 use fcreatecnn, fclosecnn, and tt_insertparm in combination to add records
4. Create a stored procedure/view for displaying data in the access query. Content :...
5. Use tt_selectparm in ASP to select data
6. Complete.
1. Create a table in the access query, named TT
Enter the following content to query and execute the statement. After execution, the table TT is created.
Linenum
- Create Table TT
- (
- Id autoincrement
- Primary Key,
- Title varchar (255 ),
- Content memo,
- Dateandtime date
- )
Note:
The ID field is automatically numbered and is the primary key.
Title is of the text type, with a length of 255
Content is the remarks type
Dateandtime is of the date type.
2. Create a query in access query with the following content:
Linenum
- Parameters sptitle varchar (255), spcontent varchar (255 );
- Insert into TT (title, content, dateandtime)
- Values ([sptitle], [spcontent], now ())
Save the name tt_insertparm
Function: Add a record to the access stored procedure
Note: In the spcontent field, the memo data type cannot be used.
3. Use tt_insertparm in ASP to add 10 records to table TT
3.1 construct the asp ado connection function, fcreatecnn and fclosecnn
Linenum
- <%
- Function fcreatecnn (CNN)
- Set CNN = Createobject ("ADODB. Connection ")
- End Function
- Function fclosecnn (CNN)
- CNN. Close
- Set CNN = nothing
- End Function
- %>
3.2 use fcreatecnn, fclosecnn, and tt_insertparm in combination to add records
Linenum
- <%
- Dim title, content
- Title = "insert title"
- Content = "insert content"
- Dim CNN, RS
- Dim I
- Call fcreatecnn (CNN)
- CNN. Open Conn
- For I = 1 to 10
- Cnn.exe cute ("Exec tt_insertparm" & Title & I & "," & content & I)
- Next
- Call fclosecnn (CNN)
- If err. Number = 0 then response. Write "data added" else response. Write "error, data not added"
- %>
4. Create a stored procedure/view for displaying data in the access query. content:
Linenum
- Parameters qid long;
- Select *
- From TT
- Where id = IIF (isnull ([qid]), ID, [qid])
Save the name tt_selectparm
Description: If the qid parameter value is null, all data is selected. Otherwise, the corresponding row of qid is selected.
5. Use tt_selectparm in ASP to select data
Linenum
- <%
- Dim qid, fldnum, I
- Qid = 10
- Dim CNN, RS
- Call fcreatecnn (CNN)
- CNN. Open Conn
- Set rs = cnn.exe cute ("Exec tt_selectparm" & qid)
- 'Set rs = cnn.exe cute ("Exec tt_selectparm null ")
- Fldnum = Rs. Fields. Count-1
- Do until Rs. EOF
- For I = 0 to fldnum
- Response. Write RS (I)
- Response. Write ""
- Next
- Response. Write "<br/>"
- Rs. movenext
- Loop
- Rs. Close
- Set rs = nothing
- Call fclosecnn (CNN)
- %>
6. Complete.
Note: There are also updates. The Stored Procedure/view for data deletion is not demonstrated. However, if you read the above operations, this should not be a problem.
From: http://blog.csdn.net/btbtd/archive/2006/08/30/1145678.aspx