创建过程范例

目录

如下代码演示怎样使用 Command 对象和 Procedures 集合 Append 方法,在基本数据源中创建新的过程。

Sub CreateProcedure()   Dim cnn As New ADODB.Connection
   Dim cmd As New ADODB.Command
   Dim prm As ADODB.Parameter
   Dim cat As New ADOX.Catalog   ' 打开连接
   cnn.Open _
      "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=c:\Program Files\Microsoft Office\" & _
      "Office\Samples\Northwind.mdb;"   ' 创建参数化命令(Jet 指定)
   Set cmd.ActiveConnection = cnn
   cmd.CommandText = "PARAMETERS [CustId] Text;" & _
      "Select * From Customers Where CustomerId = [CustId]"   ' 打开目录
   Set cat.ActiveConnection = cnn   ' 创建新过程
   cat.Procedures.Append "CustomerById", cmdEnd Sub
www.holmesian.org