学院首页>网络编程>其它编程>在 Access 中使用“存储过程”

在 Access 中使用“存储过程”

作者: 来源: 添加时间:2006-5-22 10:57:26
使用存储过程

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

  这里可以看到为什么我说 Access 中的查询就是它的存储过程——我们的 Command 对象的 CommandType 属性设置的是 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 "<ul>"
  Dim i
  For i = 0 To UBound(resultArray, 2)
  Response.Write "<li>" & resultArray(0, i)
  Response.Write " " & resultArray(1, i)
  Response.Write " " & resultArray(2, i)
  Response.Write "</li>"
  Next
  Response.Write "</ul>"
  %>

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

  运行结果。

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

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

第 3 页,共 3 页 [1] [2] [3]
站内搜索