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

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  Insert com várias tabelas?
Tamanini
não registrado
Postada em 01/02/2005 16:33 hs   
Isso é possível, com apenas um insert eu inserir os dados em mais de uma tabela?
No meu caso são duas tabelas que estão enormes, eu apenas gerei o SQL, falta arrumar os valores, não repare nas buscas de valores em outros forms, é que dividi em 4 forms os dados que serão armazenados em 2 tabelas.
Ex:
strSQL = "INSERT INTO tblAparelho(fk_cod_emp,nAp_ap,nPed_ap,discriped_ap,dt_saida_ap,"
    strSQL = strSQL & "epromV_ap,Nestu_ap,pCom_ap,AcopRele_ap,Revers_ap,Hertz_ap,ap2051_ap,2051gab_ap,"
    strSQL = strSQL & "apdpc_ap,dpcgab_ap,apcrt_ap,crtgab_ap,apcrp_ap,crpgab_ap,npBar_ap,"
    strSQL = strSQL & "dt_montBar_ap,shabAqBar_ap,shabRenBar_ap,pCPU_ap,dt_montCPU_ap,pConv_ap,dt_montConv_ap,"
    strSQL = strSQL & "calibGAmpConv_ap,caliboffsetConv_ap,lacretrimpConv_ap,med_umiConv_ap,pRele_ap,dt_montRele_ap,"
    strSQL = strSQL & "ctoConrtRele_ap,aquecRele_ap,renovRele_ap,ctoTenRele_ap,TeRevmotRele_ap,AcioLedRele_ap,pTecla_ap,"
    strSQL = strSQL & "dt_montTecla_ap,obs_ap)VALUES(" & iCodEmpAp & "," & txtAparelho.Text & "," & txtPed.Text & ",'" & strDiscrPed & "','" & txtDtS.Text & "',"
    strSQL = strSQL & txtEprom.Text & "," & txtNEstufa.Text & ",'" & bPCom & "','" & iAcRele & "','" & iRevers & "','" & iHertz & "','" & chkDmc2051.Value & "','" & chkGDmc2051.Value & "',"
    strSQL = strSQL & "'" & chkDpc2251.Value & "','" & chkGDpc2251.Value & "','" & chkCrt04.Value & "','" & chkGCrt04.Value & "','" & chkCrp03.Value & "','" & chkGCrp03.Value & "','" & frmHistorico.txtNBar.Text & "',"
    strSQL = strSQL & "'" & frmHistorico.txtDBar.Text & "','" & bsHAqBar & "','" & bsHRenBar & "','" & frmHistorico.txtNCpu.Text & "','" & frmHistorico.txtDCpu.Text & "','" & frmHistorico.txtNConv.Text & "','" & frmHistorico.txtDConv.Text & "',"
    strSQL = strSQL & "'" & frmHistorico.chkCGAmp.Value & "','" & frmHistorico.chkCOffset.Value & "','" & frmHistorico.chkLacTrim.Value & "','" & strMedUmi & "','" & frmHistorico.txtNRele.Text & "','" & frmHistorico.txtDRele.Text & "',"
    strSQL = strSQL & "'" & bctoCteR & "','" & iAqRel & "','" & iRenRel & "','" & strCTRele & "','" & frmHistorico.chkTMRevM.Value & "','" & frmHistorico.chkAcLeds.Value & "','" & frmHistorico.txtNTecl.Text & "',"
    strSQL = strSQL & "'" & frmHistorico.txtDTecl.Text & "','" & txtObs.Text & "')"
    dbDados.Execute strSQL
    

'##############  2º Tabela
    strSQL = "INSERT INTO tblChkList(fk_cod_ap,fk_cod_emp,tmDes_list,tmZval_list,calendDtH,"
    strSQL = strSQL & "set00_list,set01_list,set02_list,set03_list,set04_list,"
    strSQL = strSQL & "set05_list,set06_list,set07_list,set08_list,set08TK_list,"
    strSQL = strSQL & "set08TN_list,set09_list,set10_list,set10TK_list,set10TN_list,"
    strSQL = strSQL & "set11_list,set12_list,set13_list,set14_list,set15_list,"
    strSQL = strSQL & "motHab_list,motRev_list,motRevH_list,motRevM_list,chpaSD_list,"
    strSQL = strSQL & "filLnSD_list,pComSD_list,JSTSD_list,FilfuSD_list,rabtoSD_list,"
    strSQL = strSQL & "banaSD_list,kit2251SD_list,kit2051SD_list,kitpinSD_list,kitermSD_list,"
    strSQL = strSQL & "CFApRSD_list,curSD_list,testSD_list,ppBar_list,CFCxCSD_list,"
    strSQL = strSQL & "eti2251SD_list,etiGab2251SD_list,eti2051SD_list,etiFFPSD_list,etiEprom_list,"
    strSQL = strSQL & "man_list)VALUES('" & iCodApLst & "','" & iCodEmpAp & "','" & frmCheckDmc2051.chkTimerD.Value & "','" & frmCheckDmc2051.chkTimerZ.Value & "','" & frmCheckDmc2051.chkCal.Value & "',"
    strSQL = strSQL & "'" & frmCheckDmc2051.chkSet00.Value & "','" & frmCheckDmc2051.chkSet01.Value & "','" & bSet02 & "','" & frmCheckDmc2051.chkSet03.Value & "','" & frmCheckDmc2051.chkSet04.Value & "',"
    strSQL = strSQL & "'" & frmCheckDmc2051.chkSet05.Value & "','" & frmCheckDmc2051.chkSet06.Value & "','" & frmCheckDmc2051.chkSet07.Value & "','" & iSet08 & "','" & frmCheckDmc2051.txtSet08TK.Text & "',"
    strSQL = strSQL & "'" & frmCheckDmc2051.txtSet08TN.Text & "','" & iSet09 & "','" & iSet10 & "','" & frmCheckDmc2051.txtSet10TK.Text & "','" & frmCheckDmc2051.txtSet10TN.Text & "',"
    strSQL = strSQL & "'" & iSet11 & "','" & frmCheckDmc2051.chkSet12.Value & "','" & frmCheckDmc2051.chkSet13.Value & "','" & bSet14 & "','" & strSet15 & "',"
    strSQL = strSQL & "'" & frmCheckDmc2051.chkMotHab.Value & "','" & frmCheckDmc2051.optMotRevS.Value & "','" & frmCheckDmc2051.chkmot3h.Value & "','" & frmCheckDmc2051.chkmot3m.Value & "','" & frmCheckSaida.chkCPacri.Value & "',"
    strSQL = strSQL & "'" & frmCheckSaida.chkFLinha.Value & "','" & frmCheckSaida.chkPComunicacao.Value & "','" & frmCheckSaida.chkJSTensao.Value & "','" & frmCheckSaida.chkFFusivel.Value & "','" & frmCheckSaida.chkRTomada.Value & "',"
    strSQL = strSQL & "'" & frmCheckSaida.chkPBanana.Value & "','" & frmCheckSaida.chkKitDpc2251.Value & "','" & frmCheckSaida.chkKitDmc2051.Value & "','" & frmCheckSaida.chkKitInser.Value & "','" & frmCheckSaida.chkKitAnilha.Value & "',"
    strSQL = strSQL & "'" & frmCheckSaida.chkFARes.Value & "','" & frmCheckSaida.chkCS23.Value & "','" & frmCheckSaida.chkTA5v.Value & "','" & frmCheckSaida.chkPPBar.Value & "','" & frmCheckSaida.chkCFConex.Value & "',"
    strSQL = strSQL & "'" & frmCheckSaida.chkEDpc2251.Value & "','" & frmCheckSaida.chkEGDpc2251.Value & "','" & frmCheckSaida.chkEGDmc2051.Value & "','" & frmCheckSaida.chkEFPainel.Value & "','" & frmCheckSaida.chkEDEprom.Value & "',"
    strSQL = strSQL & "'" & frmCheckSaida.chkManual.Value & "')"
    dbDados.Execute strSQL
     
Mateus
AMADORA
PT - PORTUGAL
Postada em 02/02/2005 11:50 hs            
De facto, ou a coisa não está bem explicada, ou faz 2 SQLs. Senão vejamos:
 
strSQL = "INSERT INTO tblAparelho(fk_cod_emp,nAp_ap,nPed_ap,discriped_ap,dt_saida_ap,"
    strSQL = strSQL & "epromV_ap,Nestu_ap,pCom_ap,AcopRele_ap,Revers_ap,Hertz_ap,ap2051_ap,2051gab_ap,"
    strSQL = strSQL & "apdpc_ap,dpcgab_ap,apcrt_ap,crtgab_ap,apcrp_ap,crpgab_ap,npBar_ap,"
    strSQL = strSQL & "dt_montBar_ap,shabAqBar_ap,shabRenBar_ap,pCPU_ap,dt_montCPU_ap,pConv_ap,dt_montConv_ap,"
    strSQL = strSQL & "calibGAmpConv_ap,caliboffsetConv_ap,lacretrimpConv_ap,med_umiConv_ap,pRele_ap,dt_montRele_ap,"
    strSQL = strSQL & "ctoConrtRele_ap,aquecRele_ap,renovRele_ap,ctoTenRele_ap,TeRevmotRele_ap,AcioLedRele_ap,pTecla_ap,"
    strSQL = strSQL & "dt_montTecla_ap,obs_ap)VALUES(" & iCodEmpAp & "," & txtAparelho.Text & "," & txtPed.Text & ",'" & strDiscrPed & "','" & txtDtS.Text & "',"
    strSQL = strSQL & txtEprom.Text & "," & txtNEstufa.Text & ",'" & bPCom & "','" & iAcRele & "','" & iRevers & "','" & iHertz & "','" & chkDmc2051.Value & "','" & chkGDmc2051.Value & "',"
    strSQL = strSQL & "'" & chkDpc2251.Value & "','" & chkGDpc2251.Value & "','" & chkCrt04.Value & "','" & chkGCrt04.Value & "','" & chkCrp03.Value & "','" & chkGCrp03.Value & "','" & frmHistorico.txtNBar.Text & "',"
    strSQL = strSQL & "'" & frmHistorico.txtDBar.Text & "','" & bsHAqBar & "','" & bsHRenBar & "','" & frmHistorico.txtNCpu.Text & "','" & frmHistorico.txtDCpu.Text & "','" & frmHistorico.txtNConv.Text & "','" & frmHistorico.txtDConv.Text & "',"
    strSQL = strSQL & "'" & frmHistorico.chkCGAmp.Value & "','" & frmHistorico.chkCOffset.Value & "','" & frmHistorico.chkLacTrim.Value & "','" & strMedUmi & "','" & frmHistorico.txtNRele.Text & "','" & frmHistorico.txtDRele.Text & "',"
    strSQL = strSQL & "'" & bctoCteR & "','" & iAqRel & "','" & iRenRel & "','" & strCTRele & "','" & frmHistorico.chkTMRevM.Value & "','" & frmHistorico.chkAcLeds.Value & "','" & frmHistorico.txtNTecl.Text & "',"
    strSQL = strSQL & "'" & frmHistorico.txtDTecl.Text & "','" & txtObs.Text & "')"
 
Aqui ele executa o SQL definido anteriormente:

    dbDados.Execute strSQL
 
 
Aqui define um novo SQL:
 
strSQL = "INSERT INTO tblChkList(fk_cod_ap,fk_cod_emp,tmDes_list,tmZval_list,calendDtH,"
    strSQL = strSQL & "set00_list,set01_list,set02_list,set03_list,set04_list,"
    strSQL = strSQL & "set05_list,set06_list,set07_list,set08_list,set08TK_list,"
    strSQL = strSQL & "set08TN_list,set09_list,set10_list,set10TK_list,set10TN_list,"
    strSQL = strSQL & "set11_list,set12_list,set13_list,set14_list,set15_list,"
    strSQL = strSQL & "motHab_list,motRev_list,motRevH_list,motRevM_list,chpaSD_list,"
    strSQL = strSQL & "filLnSD_list,pComSD_list,JSTSD_list,FilfuSD_list,rabtoSD_list,"
    strSQL = strSQL & "banaSD_list,kit2251SD_list,kit2051SD_list,kitpinSD_list,kitermSD_list,"
    strSQL = strSQL & "CFApRSD_list,curSD_list,testSD_list,ppBar_list,CFCxCSD_list,"
    strSQL = strSQL & "eti2251SD_list,etiGab2251SD_list,eti2051SD_list,etiFFPSD_list,etiEprom_list,"
    strSQL = strSQL & "man_list)VALUES('" & iCodApLst & "','" & iCodEmpAp & "','" & frmCheckDmc2051.chkTimerD.Value & "','" & frmCheckDmc2051.chkTimerZ.Value & "','" & frmCheckDmc2051.chkCal.Value & "',"
    strSQL = strSQL & "'" & frmCheckDmc2051.chkSet00.Value & "','" & frmCheckDmc2051.chkSet01.Value & "','" & bSet02 & "','" & frmCheckDmc2051.chkSet03.Value & "','" & frmCheckDmc2051.chkSet04.Value & "',"
    strSQL = strSQL & "'" & frmCheckDmc2051.chkSet05.Value & "','" & frmCheckDmc2051.chkSet06.Value & "','" & frmCheckDmc2051.chkSet07.Value & "','" & iSet08 & "','" & frmCheckDmc2051.txtSet08TK.Text & "',"
    strSQL = strSQL & "'" & frmCheckDmc2051.txtSet08TN.Text & "','" & iSet09 & "','" & iSet10 & "','" & frmCheckDmc2051.txtSet10TK.Text & "','" & frmCheckDmc2051.txtSet10TN.Text & "',"
    strSQL = strSQL & "'" & iSet11 & "','" & frmCheckDmc2051.chkSet12.Value & "','" & frmCheckDmc2051.chkSet13.Value & "','" & bSet14 & "','" & strSet15 & "',"
    strSQL = strSQL & "'" & frmCheckDmc2051.chkMotHab.Value & "','" & frmCheckDmc2051.optMotRevS.Value & "','" & frmCheckDmc2051.chkmot3h.Value & "','" & frmCheckDmc2051.chkmot3m.Value & "','" & frmCheckSaida.chkCPacri.Value & "',"
    strSQL = strSQL & "'" & frmCheckSaida.chkFLinha.Value & "','" & frmCheckSaida.chkPComunicacao.Value & "','" & frmCheckSaida.chkJSTensao.Value & "','" & frmCheckSaida.chkFFusivel.Value & "','" & frmCheckSaida.chkRTomada.Value & "',"
    strSQL = strSQL & "'" & frmCheckSaida.chkPBanana.Value & "','" & frmCheckSaida.chkKitDpc2251.Value & "','" & frmCheckSaida.chkKitDmc2051.Value & "','" & frmCheckSaida.chkKitInser.Value & "','" & frmCheckSaida.chkKitAnilha.Value & "',"
    strSQL = strSQL & "'" & frmCheckSaida.chkFARes.Value & "','" & frmCheckSaida.chkCS23.Value & "','" & frmCheckSaida.chkTA5v.Value & "','" & frmCheckSaida.chkPPBar.Value & "','" & frmCheckSaida.chkCFConex.Value & "',"
    strSQL = strSQL & "'" & frmCheckSaida.chkEDpc2251.Value & "','" & frmCheckSaida.chkEGDpc2251.Value & "','" & frmCheckSaida.chkEGDmc2051.Value & "','" & frmCheckSaida.chkEFPainel.Value & "','" & frmCheckSaida.chkEDEprom.Value & "',"
    strSQL = strSQL & "'" & frmCheckSaida.chkManual.Value & "')"
Aqui ele executa novo SQL.Aqui ele executa novo SQL.
    dbDados.Execute strSQL
 
NOTA: Não verifiquei se as strings SQL estão bem ou mal construídas.

 


    


João Mateus

Se precisar de ajuda extra, visite:

http://joaomateus.planetaclix.pt

     
Snake
Pontos: 2843
ITAJUBÁ
MG - BRASIL
Postada em 02/02/2005 12:00 hs         
cara....não entendi nada...vc quer que com apenas um INSERT adicionar dados em 2 tabelas? sua string esta muito confusa...explique melhor se possivel.


sem mais,
     
Tamanini
não registrado
Postada em 02/02/2005 13:32 hs   
É isso:
"um INSERT adicionar dados em 2 tabelas"
Mas não tem como pelo que andei vendo, correto? Vou ter que fazer dois insert mesmo!
     
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