USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  VB com SQLSERVER - StoreProcedure
Alan
Pontos: 2843
SÃO PAULO
SP - BRASIL
Postada em 06/07/2004 12:17 hs            
Galera,
 
Tenho um StoreProcedure com um insert e um select. E posivel executar esta storeprocedure e retorna o recordset.
 
Tentei desta maneira mas nao esta funcionando.
 
Set rst_retorna_Caixa = cnn_servidor.Execute("sp_Teste " & ID_Caixa & "," & !Unid & ",'" & Format(!Abertura, "mm/dd/yyyy") & "','" & FormatDateTime(!HoraA, vbLongTime) & "'," & !OperA & ",'" & Format(!Fechamento, "mm/dd/yyyy") & "','" & FormatDateTime(!HoraF, vbLongTime) & "'," & !OperF & ", 0")
 
Inclui o registro mas nao retorna recordset
 
Exemplo da StoreProcedure
 
StoreProcedure Teste
    @Var1 int, @VAr2 ..., @Var3....
as
   insert into Tabela ( 1,1,1) values Blabla
 
select CAMPO FROM TABELA X
 
GO
 
 
 
 
     
ACG1504
Pontos: 2843 Pontos: 2843
PATOS DE MINAS
MG - BRASIL
Postada em 06/07/2004 14:16 hs            
StoreProcedure Teste
    @Var1 int output, @VAr2 output ..., @Var3 output
as
   insert into Tabela ( 1,1,1) values Blabla
 
select CAMPO FROM TABELA X
 
GO
 
     
Randsolo
BELO HORIZONTE
MG - BRASIL
Postada em 06/07/2004 14:22 hs            
Eu uso desta forma:
'/////////////////////////////////////////////////////////////////////
Na Stored Procedure:
CREATE PROC DBO.MNBANCO
 @CodBco  char (03),
 @NomBco  varchar (30),
 @CodUsuSis      integer,
 @FlagOper    char(1)
 AS
        IF @FlagOper = 'I'
           INSERT INTO BANCO
        (CodBco,
         NomBco,
         CodUsuSis,
         DatUltAlt)
  VALUES
         (@CodBco,
          @NomBco,
          @CodUsuSis,
          convert(datetime, getdate(), 103))
  ELSE
        BEGIN
                IF @FlagOper = 'A'
     UPDATE BANCO SET
          NomBco = @NomBco,
          CodUsuSis = @CodUsuSis,
          DatUltAlt = convert(datetime, getdate(), 103)
     WHERE CodBco = @CodBco
     END
GO
 
'/////////////////////////////////////////////////////////////////////
No Programa para Gravar ou Incluir:
'Obs: A conexão vc usa a sua
Public Conexao  As ADODB.Connection
Public Cmd      As ADODB.Command
Private Sub GravaBanco()
   Conexao.BeginTrans
   
   Set Cmd = New Command
   With Cmd
      .CommandText = "{call MNBANCO (?,?,?,?)}"
      .CommandType = adCmdText
      .ActiveConnection = Conexao
      .Parameters.Refresh
      .Parameters(0).Value = slCodBco
      .Parameters(1).Value = slNomBco
      .Parameters(2).Value = LgCodUsuSis
      .Parameters(3).Value = slFlagOper
   End With
   
   Set Rs = Cmd.Execute
   Set Rs = Nothing
   Set Cmd = Nothing
   
   Conexao.CommitTrans
End sub
 
Onde: slFlagOper é uma variável onde defino se é "I" para inclusão ou "A" para alteração;
 
Para ler eu uso um Recordset normal mesmo, usando esta função:
'PROCEDURE PARA EXECUTAR CONSULTAS NO BANCO DE DADOS
Public Sub consulta(sql As String)
    Set Rs = Nothing
    Set Rs = New ADODB.Recordset ' INSTANCIAR VARIAVEL ASSOCIADA AO BANCO DE DADOS
    With Rs
        .CursorType = adOpenKeyset 'TIPO DE NAVEGACAO
        .LockType = adLockReadOnly  'FAZ A CONSULTA "SOMENTE LEITURA NA TABELA"
        .Source = sql 'String de comandos ao Banco de Dados
        .ActiveConnection = Conexao ' ATIVA A CONEXAO COM O BANCO DE DADOS
        .Open 'ABRE O BANCO DE DADOS
    End With
End Sub
e chamo assim:
call consulta("SELECT CodBco, NomBco FROM Banco")
 
Acho q isto deve te ajudar!!!  Emoções
Qq coisa me avisa!
 
 
"Que a Força esteja com vc..."
     
Página(s): 1/1    


Seu Nome:

Seu eMail:

ALTERAR PARA MODO HTML
Mensagem:

[:)] = 
[:P] = 
[:(] = 
[;)] = 

HTML DESLIGADO

     
 VOLTAR

  



CyberWEB Network Ltda.    © Copyright 2000-2025   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página