如何在vb中使用SQL Server数据库中的存储过程?
  能按照事先写好的存储过程来修改数据库.

解决方案 »

  1.   

    你可以使用 ADODB.Command 来调用存储过程,如: Dim adoComm As Object 
    '// 创建一个对象,我们用来调用存储过程 
    Set adoComm = CreateObject("ADODB.Command") 
    With adoComm 
    '// 设置连接,假设 adoConn 为已经连接的 ADODB.Connection 对象 
    .ActiveConnection = adoConn 
    '// 类型为存储过程,adCmdStoredProc = 4 
    .CommandType = 4 
    '// 存储过程名称 
    .CommandText = "你的存储过程名称" 
    '// 设置输入参数 
    .Parameters.Item("@输入参数").Value = "值" 
    '// 执行存储过程 
    .Execute If .Parameters.Item("@返回参数名称").Value = True Then Else End If 
    End With 
    '// 释放对象 
    Set adoComm = Nothing
      

  2.   

    Dim strPara As String
        Dim adoConn As ADODB.Connection
        Dim strCnn As String
        Dim Cmd As New ADODB.Command
        Dim Rst As New ADODB.Recordset
        Set adoConn = New ADODB.Connection
        strCnn = "Provider=sqloledb;Data Source=;Initial Catalog=;User Id=;Password=; "
        adoConn.Open strCnn
        adoConn.CursorLocation = adUseClient
        Cmd.ActiveConnection = adoConn
        Cmd.CommandText = "au_info"
        Cmd.CommandType = adCmdStoredProc
        Cmd.CommandTimeout = 0
        Cmd.Parameters("@userid") = "1"
        Set Rst = Cmd.Execute
        If Rst.RecordCount = 0 Then
            Exit Sub
        Else
            Rst.MoveFirst
            MsgBox Rst.Fields("userid").Value, vbYesNo, "你好"
        End If
        adoConn.Close
      

  3.   

    也可以按常规的执行 SQL 语句来执行存储过程嘛,即用:Exec 存储过程名 参数列表