Hello. I've made a code to online insert a TXT file into an Access database(MDB) file It is the second code like this i built. The first one, had the problem that it could convert only one time...the second time it do not work. This one,now...it looks like will work(don't know,i got an error)...but i need the help of u all to test. Here's the code...i am getting the error: Microsoft JET Database Engine error '80040e14' Syntax error in query expression 'cod;nome;telefone;email'. /pablo/conversor2.asp, line 43 <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <% 'Convertendo TXT diretamente para MDB online - By Pablo 'Declaração das variáveis Dim fsoObject Dim filObject Dim tsObject Dim strBuffer Dim objConn, objRS,Sql 'Criando o objeto de conexão ADO set objConn=server.CreateObject("ADODB.Connection") 'Criando o Recordset set objrs=server.CreateObject("ADODB.Recordset") 'Informando o driver a ser usado, e o local aonde se encontra o banco de dados de destino. objConn.Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =" & server.MapPath ("conv.mdb") Const ForReading = 1 Const TristateFalse = 0 'Crio o objeto FSO(File System Object) Set fsoObject = Server.CreateObject("Scripting.FileSystemObject") 'Com o FSO, abro o arquivo txt Set filObject = fsoObject.GetFile(server.MapPath ("arquivo.txt")) 'Abro ele para leitura,indicando os parâmetros pré-definidos set tsObject = filObject.OpenAsTextStream(ForReading,TristateFalse) %> <title>Converte TXT para MDB</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <% 'Loop para inserir na tabela do While Not tsObject.AtEndOfStream 'Atribuo a strline, a leitura de cada linha do arquivo strLine = tsObject.ReadLine 'Sintaxe SQL para inserir dentro do banco sql = "insert into tabela (cod,nome,telefone,email) values ("&strLine&")" '===>This is the line where i think the error is 'Inserindo dentro do banco set objrs=objconn.execute(sql) '===>This is the line 43 'Fazer o loop loop 'Fim do código %> </body> </html> Code (markup):
this looks like a complicated script. What language and can ypu please post the format of ur second table like maro said have a nice day
It looks like your SQL is F'd up - please show us your variable strLine Also - is it being protected? (as in are you removing the ' ticks for sql injection)? Someone might be trying to hack you...
You already have your string inside strLine variable right? Then do no enclose it into quotes as it's already a string variable. Try sql = "insert into tabela (cod,nome,telefone,email) values (strLine)" instead of sql = "insert into tabela (cod,nome,telefone,email) values ("&strLine&")" and this is according the fact that strLine contains 4 values separated with the default field separators and that they are the same type as your db fields off course..
Here's a easy way to solve your problem. Since you are looping, just print out the 1st sql. Then execute that sql in Access. At this point, you should be able to see what the problem is. My guess is that you did not quote one or more columns.