vb创建SQL的存储过程,需要用哪些语句,能否写个例子,谢谢呀,给一白分呀

解决方案 »

  1.   

    Public conn As New ADODB.Connection
    conn.Open "....."连接数据库 
    conn.Execute "if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[P_XG]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" & _
                  " drop procedure [dbo].[P_XG] "
         conn.Execute " CREATE PROCEDURE  P_XG AS DECLARE @dh varchar(13),@xj money,@kje money,@xj1 money,@kje1 money " & _
                  " select @dh='2006040500012' select @xj=sum(xj),@kje=sum(kje)  from xsjeb_18 where ph=1 select @xj1=xj,@kje1=kje from sjxszd where dh=@dh" & _
                  " update sjxszd set yskhj=@xj+@kje,xj=@xj,kje=@kje where dh=@dh  "
      

  2.   

    调用 SQLDMO 对象就比较简单。    Dim objSvr As New SQLDMO.SQLServer
        Dim objdb As New SQLDMO.Database
        Dim objsp As New SQLDMO.StoredProcedure
        
        objSvr.Connect "sql server服务器名", "sa", ""
        
        Set objdb = objSvr.Databases("数据库名")
        objsp.Name = "test"         '存储过程名称
        objsp.Text = Text1.Text     '用来输入存储过程的 t-sql 代码,可以很长,但必须符合语法
        
        objdb.StoredProcedures.Add objsp
        
        
        objSvr.DisConnect
        objSvr.Close
      

  3.   

    修改的话更简单:    Set objsp = objdb.StoredProcedures("test")   '取得存储过程对象
        objsp.Alter Text1.Text         '新存储过程的 t-sql 代码
      

  4.   

    但是在VB里面用存储过程,每一行都得加这个"& _",很麻烦,有其它方法没有
      

  5.   

    "& _"这是连接符号,为了一行不要太长而方便观看的。
      

  6.   

    执行一下创建过程的SQL语句就可以了
      

  7.   

    执行 创建 SP Script 语句就行了