使用存儲過程
然后我們可以在 ASP 程序中調(diào)用這些存儲過程了。
這里可以看到為什么我說 access 中的查詢就是它的存儲過程——我們的 Command 對象的 CommandType 屬性設(shè)置的是 4,即 Stored Proc!
so...
以下的代碼很簡單:
代碼:
--------------------------------------------------------------------------------
<%
Option Explicit
Dim s
Randomize
s = Rnd * 100
Dim conn, cmd
Set conn = Server.CreateObject("ADODB.Connection")
Set cmd = Server.CreateObject("ADODB.Command")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("sp.mdb")
With cmd
.ActiveConnection = conn
.CommandType = &H0004 '存儲過程
.CommandText = "AddNewData"
End With
cmd.Execute , Array(CStr(Now()), CSng(s))
With cmd
.ActiveConnection = conn
.CommandType = &H0004 '存儲過程
.CommandText = "GetData"
End With
Dim resultRS, resultArray
Set resultRS = cmd.Execute(, Null)
If Not resultRS.EOF Then
resultArray = resultRS.GetRows()
End If
Set resultRS = Nothing
Set cmd = Nothing
conn.Close
Set conn = Nothing
Response.Write "
%>
然后我們可以在 ASP 程序中調(diào)用這些存儲過程了。
這里可以看到為什么我說 access 中的查詢就是它的存儲過程——我們的 Command 對象的 CommandType 屬性設(shè)置的是 4,即 Stored Proc!
so...
以下的代碼很簡單:
代碼:
--------------------------------------------------------------------------------
<%
Option Explicit
Dim s
Randomize
s = Rnd * 100
Dim conn, cmd
Set conn = Server.CreateObject("ADODB.Connection")
Set cmd = Server.CreateObject("ADODB.Command")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("sp.mdb")
With cmd
.ActiveConnection = conn
.CommandType = &H0004 '存儲過程
.CommandText = "AddNewData"
End With
cmd.Execute , Array(CStr(Now()), CSng(s))
With cmd
.ActiveConnection = conn
.CommandType = &H0004 '存儲過程
.CommandText = "GetData"
End With
Dim resultRS, resultArray
Set resultRS = cmd.Execute(, Null)
If Not resultRS.EOF Then
resultArray = resultRS.GetRows()
End If
Set resultRS = Nothing
Set cmd = Nothing
conn.Close
Set conn = Nothing
Response.Write "
- "
- " & resultArray(0, i)
Response.Write " " & resultArray(1, i)
Response.Write " " & resultArray(2, i)
Response.Write " "
Dim i
For i = 0 To UBound(resultArray, 2)
Response.Write "
Next
Response.Write "
%>