Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Eu to fazendo uma pagina pra faze uma exportação de dados de um arquivo *.csv para um banco de dados Access. Até ai tudo bem.
Mas ta dando um erro no WEND do loop que eu faço, e não sei o porque. Já verifiquei se era algum IF sem fechar, outro WHILE, mas nada... :(
O erro acusa na linha em vermelho. Segue o código:
<%
Server.ScriptTimeout = 999999999
Response.Buffer = true
%>
<!-- #include file="../includes/open_conn.asp"-->
<!-- #include file="../includes/fobjvbs.inc"-->
<%
'// Importa Funcionarios
vid_empresa = "1539"
x = 0
Set obj = CreateObject("Scripting.FileSystemObject")
Set arquivo = obj.OpenTextFile(server.mappath("gpnet/gpnet.csv"), forreading, FALSE)
While not arquivo.AtEndOfStream
x = x + 1
linha = arquivo.readline
dados = split(linha, ";")
empresa = dados(0)
subdivisao = dados(1)
matricula = dados(2)
data_inicio = dados(3)
cargo = dados(4)
setor = dados(5)
nome = dados(6)
estado_civil = dados(7)
data_nascimento = dados(8)
rg = dados(9)
ctps = dados(10) & ", " & dados(11) & "/" & dados(12)
endereco = dados(13)
'verifica setor
SQL = "SELECT * FROM tab_setores WHERE desc_set='" & setor & "'"
set tab_setores = conn.execute(SQL)
if not tab_setores.eof and not tab_setores.bof then
cod_set = tab_setores("cod_set")
else
SQL = "INSERT INTO tab_setores(desc_set) VALUES('" & setor & "')"
Conn.execute SQL
'pega o código do novo setor
set tb_get = conn.execute("SELECT MAX(cod_set) AS ultimo FROM tab_setores")
cod_set = tb_get("ultimo")
set tb_get = nothing
end if
set tab_setores = nothing
'verifica funcao
SQL = "SELECT * FROM tab_funções WHERE desc_fun='" & cargo & "'"
set tab_funcoes = conn.execute(SQL)
if not tab_funcoes.eof and not tab_funcoes.bof then
cod_fun = tab_funcoes("cod_fun")
else
SQL = "INSERT INTO tab_funcoes(desc_fun) VALUES('" & cargo & "')"
Conn.execute SQL
'pega o código da nova função
set tb_get = conn.execute("SELECT MAX(cod_fun) AS ultimo FROM tab_funcoes")
cod_fun = tb_get("ultimo")
set tb_get = nothing
end if
set tab_funcoes = nothing
'Verifica empresa
SQL = "SELECT * FROM tab_empresas WHERE razo_emp='" & empresa & "'"
set tab_empresas = conn.execute(SQL)
if not tab_empresas.eof and not tab_empresas.bof then
cod_emp = tab_empresas("cod_emp")
else
'########## INSERE NOVAS EMPRESAS NO POLUX
SQL = "" &_
"INSERT INTO " &_
"tab_empresas" &_
"(fant_emp, " &_
"raso_emp, " &_
"ie_emp, " &_
"contr_emp, " &_
"venc_emp, " &_
"seg_emp, " &_
"end_emp, " &_
"cid_emp, " &_
"cep_emp, " &_
"uf_emp, " &_
"pagto_emp, " &_
"cgc_emp, " &_
"cnae_emp) " &_
"VALUES" &_
"('" & replace(empresa, "'", "''") & "', " &_
"'" & replace(empresa, "'", "''") & "', " &_
"' ', " &_
"0, " &_
"01/01/2003, " &_
"0, " &_
"'" & endereco & "', " &_
"' ', " &_
"' ', " &_
"' ', " &_
"1, " &_
"' ', " &_
"' ')"
Conn.Execute SQL
'pega o código da empresa
set tb_get = conn.execute("SELECT MAX(cod_emp) AS ultimo FROM tab_empresas")
cod_emp = tb_get("ultimo")
set tb_get = nothing
end if
set tab_empresas = nothing
'verifica setor p/ empresa
SQL = "SELECT * FROM tab_set_emp WHERE cod_emp_setemp=" & cod_emp & " AND cod_set_setemp=" & cod_set
set tab_set_emp = conn.execute(SQL)
if not tab_set_emp.eof = false and not tab_set_emp.bof = false then
SQL = "INSERT INTO tab_set_emp(cod_emp_setemp,cod_set_setemp) VALUES(" & cod_emp & "," & cod_set & ")"
Conn.execute SQL
'pega o código da nova função
' set tb_get = conn.execute("SELECT MAX(cod_fun) AS ultimo FROM tab_funcoes")
' cod_fun = tb_get("ultimo")
' set tb_get = nothing
' end if
set tab_set_emp = nothing
'verifica função p/ setor
SQL = "SELECT * FROM tab_fun_set WHERE cod_emp_funset=" & cod_emp & " AND cod_set_funset=" & cod_set & " AND cod_fun_funset=" & cod_fun
set tab_fun_set = conn.execute(SQL)
if not tab_fun_set.eof = false and not tab_fun_set.bof = false then
SQL = "INSERT INTO tab_fun_set(cod_emp_funset,cod_set_funset,cod_fun_funset) VALUES(" & cod_emp & "," & cod_set & "," & cod_fun & ")"
Conn.execute SQL
'pega o código da nova função
' set tb_get = conn.execute("SELECT MAX(cod_fun) AS ultimo FROM tab_funcoes")
' cod_fun = tb_get("ultimo")
' set tb_get = nothing
' end if
set tab_fun_set = nothing
'verifica função p/ setor
SQL = "SELECT * FROM tab_fun_set WHERE cod_emp_funset=" & cod_emp & " AND cod_set_funset=" & cod_set & " AND cod_fun_funset=" & cod_fun
set tab_fun_set = conn.execute(SQL)
if not tab_fun_set.eof = false and not tab_fun_set.bof = false then
SQL = "INSERT INTO tab_fun_set(cod_emp_funset,cod_set_funset,cod_fun_funset) VALUES(" & cod_emp & "," & cod_set & "," & cod_fun & ")"
Conn.execute SQL
'pega o código da nova função
' set tb_get = conn.execute("SELECT MAX(cod_fun) AS ultimo FROM tab_funcoes")
' cod_fun = tb_get("ultimo")
' set tb_get = nothing
' end if
set tab_fun_set = nothing
'Cadastra um trabalhador
SQL = "INSERT INTO tab_trabalhadores(nome,sexo,situ_tra,nasc_tra,doc_tra,est_tra,seq_tra,audio_tra,
obs_tra,acha_trab,adm_trab,rg_trab,ctps_trab,pis_trab,empregos_trab) VALUES('" & nome & "','Masculino',0,'" & data_nascimento & "','',0,,'Sim','',,'','" & rg & "','" & ctps & "','','')"
Conn.execute(SQL)
'Pega o ID do ultimo trabalhador cadastrado
SQL = "SELECT MAX(cod_tra) As cod_tra FROM Tab_Trabalhadores"
Set tb_temp_tra = conn.execute(SQL)
cod_tra = tb_temp_tra("cod_tra")
'Insere os valores do setor, função, empresa e trabalhador na tabela tb_tra_fun
SQL = "INSERT INTO tab_tra_fun(cod_emp_trafun,cod_set_trafun,cod_fun_trafun,cod_tra_trafun) VALUES(" & cod_emp & "," & cod_set & "," & cod_fun & "," & cod_tra & ")"
COnn.execute(SQL)
'SQL = ""
'SQL = "INSERT INTO tb_funcionario(id_tb_empresa, cod_tb_funcionario, nome_tb_funcionario, sexo_tb_funcionario, dt_nascimento_tb_funcionario, ctps_tb_funcionario) " &_
' "VALUES(" & vid_empresa & ", '" & codigo & "', '" & nome & "', '" & sexo & "', '" & nascimento & "', '" & ctps & "')"
'Conn.execute SQL
wend
arquivo.Close
set arquivo=nothing
set obj=nothing
Response.Write "<BR><BR>" & x & " Funcionarios Importados com sucesso"
%>
Se alguém puder me ajudar agradeço. ^_^
o erro está num dos seus end ifs. .....procure todos, e verifique todos q sao abertos e fechados dentro do while ..wendja quebrei a cabeça por erros assim.....conte tdos if e end if
Acho que erro já começa pelo seu primeiro end if comentado.
veja:
'verifica setor p/ empresa
SQL = "SELECT * FROM tab_set_emp WHERE cod_emp_setemp=" & cod_emp & " AND cod_set_setemp=" & cod_set
set tab_set_emp = conn.execute(SQL)
if not tab_set_emp.eof = false and not tab_set_emp.bof = false then
SQL = "INSERT INTO tab_set_emp(cod_emp_setemp,cod_set_setemp) VALUES(" & cod_emp & "," & cod_set & ")"
Conn.execute SQL
'pega o código da nova função
' set tb_get = conn.execute("SELECT MAX(cod_fun) AS ultimo FROM tab_funcoes")
' cod_fun = tb_get("ultimo")
' set tb_get = nothing
' end if
set tab_set_emp = nothing
'verifica função p/ setor
SQL = "SELECT * FROM tab_fun_set WHERE cod_emp_funset=" & cod_emp & " AND cod_set_funset=" & cod_set & " AND cod_fun_funset=" & cod_fun
set tab_fun_set = conn.execute(SQL)
if not tab_fun_set.eof = false and not tab_fun_set.bof = false then
SQL = "INSERT INTO tab_fun_set(cod_emp_funset,cod_set_funset,cod_fun_funset) VALUES(" & cod_emp & "," & cod_set & "," & cod_fun & ")"
Conn.execute SQL
'pega o código da nova função
' set tb_get = conn.execute("SELECT MAX(cod_fun) AS ultimo FROM tab_funcoes")
' cod_fun = tb_get("ultimo")
' set tb_get = nothing
' end if
set tab_fun_set = nothing
'verifica função p/ setor
SQL = "SELECT * FROM tab_fun_set WHERE cod_emp_funset=" & cod_emp & " AND cod_set_funset=" & cod_set & " AND cod_fun_funset=" & cod_fun
set tab_fun_set = conn.execute(SQL)
if not tab_fun_set.eof = false and not tab_fun_set.bof = false then
SQL = "INSERT INTO tab_fun_set(cod_emp_funset,cod_set_funset,cod_fun_funset) VALUES(" & cod_emp & "," & cod_set & "," & cod_fun & ")"
Conn.execute SQL
'pega o código da nova função
' set tb_get = conn.execute("SELECT MAX(cod_fun) AS ultimo FROM tab_funcoes")
' cod_fun = tb_get("ultimo")
' set tb_get = nothing
' end if
set tab_fun_set = nothing
'Cadastra um trabalhador
SQL = "INSERT INTO tab_trabalhadores(nome,sexo,situ_tra,nasc_tra,doc_tra,est_tra,seq_tra,audio_tra,
obs_tra,acha_trab,adm_trab,rg_trab,ctps_trab,pis_trab,empregos_trab) VALUES('" & nome & "','Masculino',0,'" & data_nascimento & "','',0,,'Sim','',,'','" & rg & "','" & ctps & "','','')"
Conn.execute(SQL)
'Pega o ID do ultimo trabalhador cadastrado
SQL = "SELECT MAX(cod_tra) As cod_tra FROM Tab_Trabalhadores"
Set tb_temp_tra = conn.execute(SQL)
cod_tra = tb_temp_tra("cod_tra")
'Insere os valores do setor, função, empresa e trabalhador na tabela tb_tra_fun
SQL = "INSERT INTO tab_tra_fun(cod_emp_trafun,cod_set_trafun,cod_fun_trafun,cod_tra_trafun) VALUES(" & cod_emp & "," & cod_set & "," & cod_fun & "," & cod_tra & ")"
COnn.execute(SQL)
'SQL = ""
'SQL = "INSERT INTO tb_funcionario(id_tb_empresa, cod_tb_funcionario, nome_tb_funcionario, sexo_tb_funcionario, dt_nascimento_tb_funcionario, ctps_tb_funcionario) " &_
' "VALUES(" & vid_empresa & ", '" & codigo & "', '" & nome & "', '" & sexo & "', '" & nascimento & "', '" & ctps & "')"
'Conn.execute SQL
wend
arquivo.Close
set arquivo=nothing
set obj=nothing
Response.Write "<BR><BR>" & x & " Funcionarios Importados com sucesso"
%>
posta o erro q da