Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido)Cadastro gigante


Matheus-vb6

Pergunta

Bom tarde gente

No meu programa do tcc, sistema de uma escola, tenho que efetuar um cadastro que tem 99 colunas, porém, pela limite de caracteres por linha, tive que fazer dessa forma

cn.Execute "insert into alunos(Graduacao,Turno,Serie,Vencimento,Anuidade,Desconto,NParcelas,NomeAluno,SobrenomeAluno,NascimentoAluno,CPFAluno,RGAluno,NomePai,SobrenomePai,NascimentoPai,CPFPai,RGPai,EnderecoPai,BairroPai,EstadoPai,CidadePai,CEPPai,ProfissaoPai,FoneResPai,FoneComPai,EmailPai,CelularPai,FoneRecPai,Nomemae,Sobrenomemae,Nascimentomae,CPFmae,RGmae,Enderecomae,Bairromae,Estadomae,Cidademae,CEPmae,Profissaomae,FoneResmae,FoneCommae,Emailmae,Celularmae,FoneRecmae,Pergunta1,Pergunta2,Pergunta3,Pergunta4,Pergunta5,Pergunta6,Pergunta7,Pergunta8,Pergunta9,Pergunta10,Pergunta11,Pergunta12,Pergunta13,Pergunta14,Pergunta15,Portugues1,Arte1,EdFisica1,Matematica1,Biologia/ciencias1,Fisica1,Quimica1,Historia,Geografia,Filosafia,Sociologia,Ingles1,Espanhol1,Portugues2,Arte2,EdFisica2,Matematica2,Biologia/ciencias2,Fisica2,Quimica2,Historia,Geografia,Filosafia," & _
"Sociologia , Ingles2, Espanhol2,Portugues3,Arte3,EdFisica3,Matematica3,Biologia/ciencias3,Fisica3,Quimica3,Historia,Geografia,Filosafia,Sociologia,Ingles3,Espanhol3)" & "VALUES('" & frmNovoAluno1.cmbGraduacao.Text & "','" & frmNovoAluno1.cmbTurno.Text & "','" & frmNovoAluno1.cmbSerie.Text & "','" & frmNovoAluno1.txtAnuidade.Text & "','" & frmNovoAluno1.txtDesconto.Text & "','" & frmNovoAluno1.cmbParcelas.Text & "','" & frmNovoAluno2.txtNomeAluno.Text & "','" & frmNovoAluno2.txtSobrenomeAluno.Text & "','" & frmNovoAluno2.txtNascimentoAluno.Text & "','" & frmNovoAluno2.txtCpfAluno.Text & "','" & frmNovoAluno2.txtRGAluno.Text & "','" & frmNovoAluno2.txtNomePai.Text & "','" & frmNovoAluno2.txtSobrenomePai.Text & "','" & frmNovoAluno2.txtNascimentoPai.Text & "','" & frmNovoAluno2.txtCPFPai.Text & "','" & frmNovoAluno2.txtRGPai.Text & "','" & frmNovoAluno2.txtEnderecoPai.Text & "'" & _
",'" & frmNovoAluno2.txtBairroPai.Text & "','" & frmNovoAluno2.cmbUFPai.Text & "','" & frmNovoAluno2.txtCidadePai.Text & "','" & frmNovoAluno2.txtCEPPai.Text & "','" & frmNovoAluno2.txtProfissaoPai.Text & "','" & frmNovoAluno2.txtFoneResPai.Text & "','" & frmNovoAluno2.txtFoneComPai.Text & "','" & frmNovoAluno2.txtEmailPai.Text & "','" & frmNovoAluno2.txtCelularPai.Text & "','" & frmNovoAluno2.txtFoneRecPai.Text & "','" & frmNovoAluno2.txtNomeMae.Text & "','" & frmNovoAluno2.txtSobrenomeMae.Text & "','" & frmNovoAluno2.txtNascimentoMae.Text & "','" & frmNovoAluno2.txtCPFMae.Text & "','" & frmNovoAluno2.txtRGMae.Text & "','" & frmNovoAluno2.txtEnderecoMae.Text & "'" & _
",'" & frmNovoAluno2.txtBairroMae.Text & "','" & frmNovoAluno2.cmbUFMae.Text & "','" & frmNovoAluno2.txtCidadeMae.Text & "','" & frmNovoAluno2.txtCEPMae.Text & "','" & frmNovoAluno2.txtProfissaoMae.Text & "','" & frmNovoAluno2.txtFoneResMae.Text & "','" & frmNovoAluno2.txtFoneComMae.Text & "','" & frmNovoAluno2.txtEmailMae.Text & "','" & frmNovoAluno2.txtCelularMae.Text & "','" & frmNovoAluno2.txtFoneRecMae.Text & "','" & txtPergunta1.Text & "','" & txtPergunta2.Text & "','" & txtPergunta3.Text & "','" & txtPergunta4.Text & "','" & txtPergunta5.Text & "','" & txtPergunta6.Text & "','" & txtPergunta7.Text & "','" & txtPergunta8.Text & "','" & txtPergunta9.Text & "','" & txtPergunta10.Text & "','" & txtPergunta11.Text & "','" & txtPergunta12.Text & "','" & txtPergunta13.Text & "','" & txtPergunta14.Text & "','" & txtPergunta15.Text & "','" & "00,00" & "','" & "00,00" & "'" & _
",'" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "')"

Ele da erro de sinstaxe na instrução insert, porem não sei se ta certo com esses & _

Agradeço a ajuda de vocês desde já :)

Editado por Matheus-vb6
Tirar a CODEBOX que estrava o layout do forum
Link para o comentário
Compartilhar em outros sites

6 respostass a esta questão

Posts Recomendados

  • 0

matheus, esse erro de sintaxe ele deve dar na hora q você tenta executar a query. se os erros fossem nos & _, ele ia acusar logo quando você estivesse escrevendo. a linha já devia ficar vermelha, não precisava nem rodar o programa.

o erro então deve ta no insert, vai ver q você pos alguma virgula a mais ou a menos ou esqueceu de fechar alguma aspa.

eu to vendo tb q você ta tentando gravar numeros como '00,00'. faca isso só se o campo estiver como texto. se estiver como numero, grave 0 direto, sem aspa simples mesmo, e se você precisar separar as casas decimais, use ponto em vez de virgula.

mas o melhor jeito pra descobrir onde ta o erro seria, em vez de escrever o insert direto no .Execute(), q você escrevesse ela numa variavel, e executasse a partir da variavel. ai quando der o erro, você le o valor da variavel no immediate e tenta executar o codigo como consulta dentro do access. ai quando der o erro, o access as vezes para o cursor na parte q estiver errada.

EDITADO:

pra simplificar o codigo tb, caso no insert estejam todos os campos da tabela, na ordem, você não precisa escrever os nomes. você pode só fazer "inserto into tabela values(...)"

Link para o comentário
Compartilhar em outros sites

  • 0
mas o melhor jeito pra descobrir onde ta o erro seria, em vez de escrever o insert direto no .Execute(), q você escrevesse ela numa variavel, e executasse a partir da variavel. ai quando der o erro, você le o valor da variavel no immediate e tenta executar o codigo como consulta dentro do access. ai quando der o erro, o access as vezes para o cursor na parte q estiver errada.

Ler pelo imediate, seria o q? nunca fiz isso kkk.

Eu fiz em uma variavel agora

inserir = "insert into alunos(Graduacao,Turno,Serie,Vencimento,Anuidade,Desconto,NParcelas,NomeAluno,SobrenomeAluno,NascimentoAluno,CPFAluno,RGAluno,NomePai,SobrenomePai,NascimentoPai,CPFPai,RGPai,EnderecoPai,BairroPai,EstadoPai,CidadePai,CEPPai,ProfissaoPai,FoneResPai,FoneComPai,EmailPai,CelularPai,FoneRecPai,Nomemae,Sobrenomemae,Nascimentomae,CPFmae,RGmae,Enderecomae,Bairromae,Estadomae,Cidademae,CEPmae,Profissaomae,FoneResmae,FoneCommae,Emailmae,Celularmae,FoneRecmae,Pergunta1,Pergunta2,Pergunta3,Pergunta4,Pergunta5,Pergunta6,Pergunta7,Pergunta8,Pergunta9,Pergunta10,Pergunta11,Pergunta12,Pergunta13,Pergunta14,Pergunta15,Portugues1,Arte1,EdFisica1,Matematica1,Biologia/ciencias1,Fisica1,Quimica1,Historia1,Geografia1,Filosafia1,Sociologia1,Ingles1,Espanhol1,Portugues2,Arte2,EdFisica2,Matematica2,Biologia/ciencias2,Fisica2,Quimica2,Historia2,Geografia2,Filosafia2," & _
"Sociologia2, Ingles2, Espanhol2,Portugues3,Arte3,EdFisica3,Matematica3,Biologia/ciencias3,Fisica3,Quimica3,Historia3,Geografia3,Filosafia3,Sociologia3,Ingles3,Espanhol3)" & "VALUES('" & frmNovoAluno1.cmbGraduacao.Text & "','" & frmNovoAluno1.cmbTurno.Text & "','" & frmNovoAluno1.cmbSerie.Text & "','" & frmNovoAluno1.txtAnuidade.Text & "','" & frmNovoAluno1.txtDesconto.Text & "','" & frmNovoAluno1.cmbParcelas.Text & "','" & frmNovoAluno2.txtNomeAluno.Text & "','" & frmNovoAluno2.txtSobrenomeAluno.Text & "','" & frmNovoAluno2.txtNascimentoAluno.Text & "','" & frmNovoAluno2.txtCpfAluno.Text & "','" & frmNovoAluno2.txtRGAluno.Text & "','" & frmNovoAluno2.txtNomePai.Text & "','" & frmNovoAluno2.txtSobrenomePai.Text & "','" & frmNovoAluno2.txtNascimentoPai.Text & "','" & frmNovoAluno2.txtCPFPai.Text & "','" & frmNovoAluno2.txtRGPai.Text & "','" & frmNovoAluno2.txtEnderecoPai.Text & "'," & _
"'" & frmNovoAluno2.txtBairroPai.Text & "','" & frmNovoAluno2.cmbUFPai.Text & "','" & frmNovoAluno2.txtCidadePai.Text & "','" & frmNovoAluno2.txtCEPPai.Text & "','" & frmNovoAluno2.txtProfissaoPai.Text & "','" & frmNovoAluno2.txtFoneResPai.Text & "','" & frmNovoAluno2.txtFoneComPai.Text & "','" & frmNovoAluno2.txtEmailPai.Text & "','" & frmNovoAluno2.txtCelularPai.Text & "','" & frmNovoAluno2.txtFoneRecPai.Text & "','" & frmNovoAluno2.txtNomeMae.Text & "','" & frmNovoAluno2.txtSobrenomeMae.Text & "','" & frmNovoAluno2.txtNascimentoMae.Text & "','" & frmNovoAluno2.txtCPFMae.Text & "','" & frmNovoAluno2.txtRGMae.Text & "','" & frmNovoAluno2.txtEnderecoMae.Text & "'," & _
"'" & frmNovoAluno2.txtBairroMae.Text & "','" & frmNovoAluno2.cmbUFMae.Text & "','" & frmNovoAluno2.txtCidadeMae.Text & "','" & frmNovoAluno2.txtCEPMae.Text & "','" & frmNovoAluno2.txtProfissaoMae.Text & "','" & frmNovoAluno2.txtFoneResMae.Text & "','" & frmNovoAluno2.txtFoneComMae.Text & "','" & frmNovoAluno2.txtEmailMae.Text & "','" & frmNovoAluno2.txtCelularMae.Text & "','" & frmNovoAluno2.txtFoneRecMae.Text & "','" & txtPergunta1.Text & "','" & txtPergunta2.Text & "','" & txtPergunta3.Text & "','" & txtPergunta4.Text & "','" & txtPergunta5.Text & "','" & txtPergunta6.Text & "','" & txtPergunta7.Text & "','" & txtPergunta8.Text & "','" & txtPergunta9.Text & "','" & txtPergunta10.Text & "','" & txtPergunta11.Text & "','" & txtPergunta12.Text & "','" & txtPergunta13.Text & "','" & txtPergunta14.Text & "','" & txtPergunta15.Text & "','" & "00,00" & "','" & "00,00" & "'," & _
"'" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "','" & "00,00" & "')"

Todos estão como textos, e no caso do "00,00" seria nota dos alunos, q viriam como 00,00 devia a mascara na edição, mas ta tudo como texto!

como ler pelo imediate?

Editado por Matheus-vb6
Link para o comentário
Compartilhar em outros sites

  • 0

matheus, quanto ao immediate, eu to sempre explicando isso por ai, então achei q tivesse falado sobre isso em algum tópico seu.

acho melhor eu fazer um tutorial sobre isso quando der...

mas é o seguinte, se você apertar Ctrl + G na janela de codigos, você vai abrir uma janelinha chamada Immediate Window. la você pode executar expressoes pra ver o resultado. por exemplo, se você digitar:

? 10 / 2
e apertar ENTER, ele te devolve 5. ou se você fizer
? UCase("kuroi")
e apertar ENTER, ele te devolve "KUROI". em resumo, você pode executar codigos pra testar o andamento do programa, já q você pode usar variaveis e funcoes q você tenha declarado (acho q so funcionam funcoes publicas). o truque do Immediate seria, depois do erro, você apertar "Debug" na janela da mensagem (ou antes de rodar o programa, você adicionaria um Break Point com F9 numa linha onde quisesse pausar a execucao. no caso, seria a linha do .Execute()), e ai você iria no Immediate e digitaria, no caso:
? inserir

e ele te daria todo o valor da variavel inserir, assim você podia olhar como fica a query toda com os valores das variaveis alem de poder executa-la no access.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...