Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

luciano

Recuperar dados txt, enviar para access

Recommended Posts

Olá pessoal, fui juntando os códigod daqui do forum e cheguei neste

abaixo só que não esta funcionando.

 

É o seguinte tenho um TXT separados com ( ; )

Ex:

campinas;SP;25;150

valinhos;SP;30;180

 

bom preciso importar esses dados para access, via página ASP

então fiz este cód abaixo mais esta dando errinhos,

na parte do FSO TXT o resto funciona.

alguem poderia me ajudar?

 

 

 

 

<%@LANGUAGE="VBSCRIPT"%>

<!--#include File="Adovbs.inc"-->

<!--#include file="fobjvbs.inc"--><html>

<head>

<title>a1</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<%

Set objConn = Server.CreateObject("ADODB.Connection")

strConnection = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="

strConnection = strConnection & Server.MapPath("banco.mdb")

objConn.Open strConnection

 

'-----------'verifica se já existe

strSql = "SELECT custo_frete From cidade Where [cidade].custo_frete = '" &custo_frete& "' "

Set objTemp = objConn.Execute(strSql)

If Not objTemp.Eof Then

 

response.redirect "ja_existe.asp"

 

else

'------ se não existe da um INSERT pegando os dados do arquivo txt

 

'--inicio do FSO----

Set fs = Server.CreateObject("Scripting.FileSystemObject")

caminho = Server.Mappath("cidades.txt")

Set txt= fs.OpenTextFile(caminho, 1,0)

 

WHILE NOT txt.AtEndOfStream

linha_txt = txt.readline

If INSTR(linha_txt,";") > 0 then

arrayx = split(linha_txt,";")

 

rs.addnew

 

if arrayx(0) <> "" then rs("cidade") = arrayx(0)

if arrayx(1) <> "" then rs("uf") = arrayx(1)

if arrayx(2) <> "" then rs("custo_frete") = arrayx(2)

if arrayx(3) <> "" then rs("km") = arrayx(3)

 

rs.update

End If

WEND

'--Fim do FSO----

 

strSql4 = "INSERT INTO cidade (cidade,uf,custo_frete,km) values ('"&cidade&"','"&uf&"','"&custo_frete&"','"&km&"') "

Set objTemp = objConn.Execute(strSql4)

 

 

%>

 

<body bgcolor="#FFFFFF" text="#000000">

ok inserido corretamente<br>

 

<%

Set Conn = nothing

Set RS = nothing

end if

objConn.close %>

 

</body>

</html>

 

 

Muito obrigado mesmo

Luciano

Compartilhar este post


Link para o post
Compartilhar em outros sites

ola.. cria um "link table" no acess, fica mais facil... depois você seleciona e manda gravar numa outra tabela...

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.