在Access中使用“存储过程”(二)


使用存储过程

然后我们可以在 ASP 程序中调用这些存储过程了。

这里可以看到为什么我说 Access 中的查询就是它的存储过程——我们的 Command 对象的 CommandType 属性设置的是 4,即 Stored Proc!

so...

以下的代码很简单:

代码:
--------------------------------------------------------------------------------

 1   
 2Option Explicit 
 3
 4  
 5
 6
 7Dim s   
 8Randomize   
 9s = Rnd * 100 
10
11  
12
13
14Dim conn, cmd   
15Set conn = Server.CreateObject("ADODB.Connection")   
16Set cmd = Server.CreateObject("ADODB.Command") 
17
18  
19
20
21conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("sp.mdb") 
22
23  
24
25
26With cmd   
27.ActiveConnection = conn   
28.CommandType = &H0004 '存储过程   
29.CommandText = "AddNewData"   
30End With 
31
32  
33
34
35cmd.Execute , Array(CStr(Now()), CSng(s)) 
36
37  
38
39
40With cmd   
41.ActiveConnection = conn   
42.CommandType = &H0004 '存储过程   
43.CommandText = "GetData"   
44End With 
45
46  
47
48
49Dim resultRS, resultArray   
50Set resultRS = cmd.Execute(, Null) 
51
52  
53
54
55If Not resultRS.EOF Then   
56resultArray = resultRS.GetRows()   
57End If 
58
59  
60
61
62Set resultRS = Nothing   
63Set cmd = Nothing   
64conn.Close   
65Set conn = Nothing 
66
67  
68
69
70Response.Write "

<ul>"
Dim i
For i = 0 To UBound(resultArray, 2)
Response.Write "<li>" &amp; resultArray(0, i)
Response.Write " " &amp; resultArray(1, i)
Response.Write " " &amp; resultArray(2, i)
Response.Write "</li>"
Next
Response.Write "</ul>

1"   

--------------------------------------------------------------------------------

运行结果。

在Access中使用“存储过程”\(二\)

感觉起来,速度似乎很快,呵呵~

不知道这样在 Access 中使用存储过程的意义大不大,不过确实很好玩

ASP 正在没落,不过我仍然很喜欢它的小快灵~

联系作者:[email protected] 或者 [email protected]

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus