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

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  CommandText muito extenso?
bordoni
CURITIBA
PR - BRASIL
Postada em 04/01/2010 10:43 hs         
Bom dia a todos. Estou aprendendo VB6 para criar uma agenda de fornecedores personalizada para minha função aqui na empresa onde trabalho. Estou adaptando um exemplo de uma apostila, mas cheguei em um ponto em que estagnei.
O programa cadastra e pesquisa fornecedores em um banco de dados mdb. Na rotina GravarDados, o programa gera um erro em tempo de execução. Aparentemente, a string que é construída em .CommandText está muito extensa (na janela locals a string aparece cortada). Segue abaixo o pedaço do código onde acontece o problema. Se alguém souber o que gera o erro e puder sugerir alguma solução, fico agradecido.

Private Sub GravarDados()
    Dim cnnComando As New ADODB.Command
    Dim vConfMsg As Integer
    Dim vErro As Boolean
    On Error GoTo errGravacao
    'Inicializa as variáveis auxiliares:
    vConfMsg = vbExclamation + vbOKOnly + vbSystemModal
    vErro = False
    'Verifica os dados digitados:
    If txtEmpresa.Text = Empty Then
        MsgBox "O campo Empresa não foi preenchido.", vConfMsg, "Erro"
        vErro = True
    End If
    If (txtTelefone1.Text = Empty And txtTelefone2.Text = Empty) Then
        MsgBox "Pelo menos um campo Telefone deve ser preenchido.", vConfMsg, "Erro"
        vErro = True
    End If
    'Se aconteceu um erro de digitação, sai da sub sem gravar:
    If vErro Then Exit Sub
    Screen.MousePointer = vbHourglass
    With cnnComando
        .ActiveConnection = cnnAgenda
        .CommandType = adCmdText
        'Verifica a operação e cria o comando SQL correspondente:
        If vInclusao Then
            'Inclusão:
            .CommandText = "INSERT INTO Fornecedor " & _
            "(CodFornec, Empresa, HomePage, Natureza, Cidade, Estado, " & _
            "Pais, Prazo, FatMinimo, Faturamento, Moeda, Regime, " & _
            "FOB, CIF, Contato1, Funcao1, Telefone1, Ramal1, Celular1, " & _
            "Fax1, Email1, MSN1, Skype1, Portugues1, Contato2, Funcao2, Telefone2, " & _
            "Ramal2, Celular2, Fax2, Email2, MSN2, Skype2, Portugues2, Revisado) VALUES ('" & _
            txtCodFornec.Text & "','" & txtEmpresa.Text & "','" & _
            txtHomePage.Text & "','" & cmbNatureza.Text & "','" & _
            txtCidade.Text & "','" & txtEstado.Text & "','" & _
            cmbPais.Text & "','" & txtPrazo.Text & "','" & _
            txtFatMinimo.Text & "','" & cmbFaturamento.Text & "','" & _
            cmbMoeda.Text & "','" & vRegime & "','" & _
            vFOB & "','" & vCIF & "','" & _
            txtContato1.Text & "','" & txtFuncao1.Text & "','" & _
            txtTelefone1.Text & "','" & txtRamal1.Text & "','" & _
            txtCelular1.Text & "','" & txtFax1.Text & "','" & _
            txtEmail1.Text & "','" & txtMSN1.Text & "','" & _
            txtSkype1.Text & "','" & vPortugues1 & "','" & txtContato2.Text & "','" & _
            txtFuncao2.Text & "','" & txtTelefone2.Text & "','" & _
            txtRamal2.Text & "','" & txtCelular2.Text & "','" & _
            txtFax2.Text & "','" & txtEmail2.Text & "','" & _
            txtMSN2.Text & "','" & txtSkype2.Text & "','" & _
            vPortugues2 & "','" & vRevisado & "');"
        Else
            'Alteração:
            .CommandText = "UPDATE Fornecedor SET " & _
            "Empresa = '" & txtEmpresa.Text & "',HomePage = '" & txtHomePage.Text & "'," & _
            "Natureza = '" & cmbNatureza.Text & "',Cidade = '" & txtCidade.Text & "'," & _
            "Estado = '" & txtEstado.Text & "',Pais = '" & cmbPais.Text & "'," & _
            "Prazo = '" & txtPrazo.Text & "',FatMinimo = '" & txtFatMinimo.Text & "'," & _
            "Faturamento = '" & cmbFaturamento.Text & "',Moeda = '" & cmbMoeda.Text & "'," & _
            "Regime = '" & vRegime & "',FOB = '" & vFOB & "'," & _
            "CIF = '" & vCIF & "',Contato1 = '" & txtContato1.Text & "'," & _
            "Funcao1 = '" & txtFuncao1.Text & "',Telefone1 = '" & txtTelefone1.Text & "'," & _
            "Ramal1 = '" & txtRamal1.Text & "',Celular1 = '" & txtCelular1.Text & "'," & _
            "Fax1 = '" & txtFax1.Text & "',Email1 = '" & txtEmail1.Text & "'," & _
            "MSN1 = '" & txtMSN1.Text & "',Skype1 = '" & txtSkype1.Text & "'," & _
            "Portugues1 = '" & vPortugues1 & _
            "Contato2 = '" & txtContato2.Text & "',Funcao2 = '" & txtFuncao2.Text & "'," & _
            "Telefone2 = '" & txtTelefone2.Text & "',Ramal2 = '" & txtRamal2.Text & "'," & _
            "Celular2 = '" & txtCelular2.Text & "',Fax2 = '" & txtFax2.Text & "'," & _
            "Email2 = '" & txtEmail2.Text & "',MSN2 = '" & txtMSN2.Text & "'," & _
            "Skype2 = '" & txtSkype2.Text & "',Portugues2 = '" & vPortugues2 & "'," & _
            "',Revisado = '" & vRevisado & ";"
        End If
        .Execute
    End With
    MsgBox "Gravação concluída com sucesso.", _
    vbApplicationModal + vbInformation + vbOKOnly, _
    "Gravação OK"
    'Chama a sub que limpa os dados do formulário:
    LimparTela
Saida:
    Screen.MousePointer = vbDefault
    Set cnnComando = Nothing
    Exit Sub
errGravacao:
    With Err
        If .Number <> 0 Then
            MsgBox "Houve um erro durante a gravação dos dados na tabela.", _
            vbExclamation + vbOKOnly + vbApplicationModal, "Erro"
            .Number = 0
            GoTo Saida
        End If
    End With
End Sub

Abs,

Glaucio Bordoni
Curitiba, PR
     
comendador
SÃO GONÇALO
RJ - BRASIL
ENUNCIADA !
Postada em 04/01/2010 15:40 hs            
MAIS PRECISAMENTE EM QUAL CAMPO ESTÁ DANDO O ERRO? VARCHAR OU INTERGER. COLOQUE UMA (') ENFRENTE AO ( ON ERRO GOTO ), E O VB IRAR LHE MOSTRAR O N° DO ERRO. AI VC COLOCA-O AKI, FICANDO MAIS FACIL A ITENTIFICAÇÃO DO MESMO  
TÓPICO EDITADO
 
bordoni
CURITIBA
PR - BRASIL
ENUNCIADA !
Postada em 04/01/2010 16:42 hs         
Olá Comendador.
O erro é -2147217913 (80040e07)
Tipo de Dados Incompatível na expressão de critério.

Eu não sabia como ver o erro. Acho que agora já tenho uma pista do que possa ser. Não parece ser tamanho de string, acho que algum campo deve estar definido de forma errada.

Obrigado!

Glaucio
   
Treze
Pontos: 2843 Pontos: 2843
SÃO VICENTE
SP - BRASIL
Postada em 05/01/2010 11:31 hs            
Colega qual é o banco de dados?
 
     
vilmarbr
Pontos: 2843
SAO PAULO
SP - BRASIL
ENUNCIADA !
Postada em 05/01/2010 19:58 hs         

bordoni,

vc deve está passando valor incorreto para algum tipo de variável ou propriedade.

verifique os tipos que está usando e faço uma validação antes de passar os valores usando funçoes do tipo isnull, isnumeric, val, cint, clng, cstr, enfim, tem um mix de funções e artifícios para vc validar os dados antes de passar para a rotina que grava os dados.

e qdo der erro, notifique o usuário via msgbox, pare a execução e coloque o foco na caixa onde deu o erro.

enfim, fica aqui a sugestão.

abç

   
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