Fórum Inserir varios registro Mysql #483248

22/06/2014

0

Pessoal, Boa noite.
Alguem pode me ajudar , por favor !
Montei esse script no Delphi, pois tenho 35 edits e um button. Assim que acionado esse button quero que todos os registros que estiverem nos edits seja inseridos nos banco Mysql.
Segue abaixo o meu codigo

sqlQuery1.Active:=False;
sqlQuery1.SQL.Clear;
sqlQuery1.SQL.Add ('insert into transporte (COD, VENCIMENTO, NOME, CPF, RG, EMISSAO,DATANASC,END,N,BAIRRO,CEP,CIDADE,UF)');
sqlQuery1.SQL.Add('insert into transporte (CNH, REGISTRO_CNH, CAT, DATA_1ª_HAB, VENC_CNH, RNTRC_ANTT,NATURALIDADE,UF2,ESTADO_CIVIL,F0NE_RES,FONE_CEL,NEXTEL,E_MAIL)');
sqlQuery1.SQL.Add ('insert into transporte(AGENCIA, CONTA, BANCO, PIS_PASEP, CURSO_MOPP,PAI,MAE,REFERENCIA_PESSOAL,CONTATO_FONE)');;
sqlQuery1.SQL.Add ('VALUES(:icod, :ivencimento, :inome, :icpf, :irg, :iemissao,:idata_nasc,:iend,:in,:ibairro,:icep,:icidade,:iuf)');
sqlQuery1.SQL.Add ('VALUES(:icnh, :iregistro_cnh, :icat, :idata_1_hab, :ivenc_cnh, :irntrc_antt,:inaturalidade,:iuf2,:iestado_civil,:ifone_res,:ifone_cel,:inextel,:ie_mail)');
sqlQuery1.SQL.Add ('VALUES(:iagencia, :iconta, :ibanco, :ipis_pasep, :icurso_mopp,:ipai,:imae,:ireferencia_pessoal,:icontato_fone)');
sqlQuery1.parambyname ('icod').Value:=Edit1.Text;
sqlQuery1.parambyname ('ivencimento').Value:=Edit2.Text;
sqlQuery1.parambyname ('inome').Value:=Edit3.Text;
sqlQuery1.parambyname ('icpf').Value:=Edit4.Text;
sqlQuery1.parambyname ('irg').Value:=Edit5.Text;
sqlQuery1.parambyname ('iemissao').Value:=edit6.Text;
sqlQuery1.parambyname ('idata_nasc').Value:=Edit7.Text;
sqlQuery1.parambyname ('iend').Value:=Edit8.Text;
sqlQuery1.parambyname ('in').Value:=Edit9.Text;
sqlQuery1.parambyname ('ibairro').Value:=Edit10.Text;
sqlQuery1.parambyname ('icep').Value:=Edit11.Text;
sqlQuery1.parambyname ('icidade').Value:=edit12.Text;
sqlQuery1.parambyname ('iuf').Value:=Edit13.Text;
sqlQuery1.parambyname ('icnh').Value:=Edit14.Text;
sqlQuery1.parambyname ('iregistro_cnh').Value:=Edit15.Text;
sqlQuery1.parambyname ('icat').Value:=Edit16.Text;
sqlQuery1.parambyname ('idata_1_hab').Value:=Edit17.Text;
sqlQuery1.parambyname ('ivenc_cnh').Value:=edit18.Text;
sqlQuery1.parambyname ('irntrc_antt').Value:=Edit19.Text;
sqlQuery1.parambyname ('inaturalidade').Value:=Edit20.Text;
sqlQuery1.parambyname ('iuf2').Value:=Edit21.Text;
sqlQuery1.parambyname ('iestado_civil').Value:=edit22.Text;
sqlQuery1.parambyname ('ifone_res').Value:=Edit23.Text;
sqlQuery1.parambyname ('ifone_cel').Value:=Edit24.Text;
sqlQuery1.parambyname ('inextel').Value:=Edit25.Text;
sqlQuery1.parambyname ('ie_mail').Value:=Edit26.Text;
sqlQuery1.parambyname ('iagencia').Value:=Edit27.Text;
sqlQuery1.parambyname ('iconta').Value:=edit28.Text;
sqlQuery1.parambyname ('ibanco').Value:=edit29.Text;
sqlQuery1.parambyname ('ipis_pasep').Value:=edit30.Text;
sqlQuery1.parambyname ('icurso_mopp').Value:=edit31.Text;
sqlQuery1.parambyname ('ipai').Value:=edit32.Text;
sqlQuery1.parambyname ('imae').Value:=edit33.Text;
sqlQuery1.parambyname ('ireferencia_pessoal').Value:=edit34.Text;
sqlQuery1.parambyname ('icontato_fone').Value:=edit35.Text;
sqlQuery1.active := TRUE;
sqlQuery1.Open;


sqlQuery1.ExecSQL;

end;
Watson Rocha

Watson Rocha

Responder

Posts

22/06/2014

Ricardo

Em parte esta correto. Porém você tem que fazer assim:
begin
query.close;
query.sql.clear;
query.sql.add('insert into.....')
params.parambyname('....');
ExecSQL;
end;

Nunca usa open e ExecSQL juntos! Open você usa quando for uma instrução select e ExecSQL quando for insert, update, delete.
Responder

Gostei + 0

22/06/2014

Ricardo

Em parte esta correto. Porém você tem que fazer assim:
begin
query.close;
query.sql.clear;
query.sql.add('insert into.....')
params.parambyname('....');
ExecSQL;
end;

Nunca usa open e ExecSQL juntos! Open você usa quando for uma instrução select e ExecSQL quando for insert, update, delete.


Depois de tudo executa um ApplyUpdates();
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar