Allora con una funzione ho eliminato le righe vuote del file txt, generando un secondo file txt.
Faccio lo split per ogni spazio del file txt (posto il codice):
codice:
<%
function pulisci(stringa)
pulisci = replace(stringa, "'", "‘")
end function
Set Conn = Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("XLS/dbTXT.mdb")
Dim objFileToRead, objFileToWrite, objFSO, strPathRead, strPathWrite
strPathRead = Server.MapPath("FileOriginale.txt")
strPathWrite = Server.MapPath("FileModificato.txt")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFileToRead = objFSO.OpenTextFile(strPathRead, 1)
Set objFileToWrite = objFSO.OpenTextFile(strPathWrite, 2, True)
Dim strTemp
Do While Not objFileToRead.AtEndOfStream
strTemp = objFileToRead.ReadLine
If strTemp <> "" Then
objFileToWrite.WriteLine(strTemp)
End If
Loop
objFileToRead.Close
objFileToWrite.Close
Set objFileToRead = Nothing
Set objFileToWrite = Nothing
Set objFSO = Nothing
Response.Write("finito
")
strPath = Server.Mappath("FileModificato.txt")
Set objFileSy = Server.CreateObject("Scripting.FileSystemObject")
Set objApriFile = objFileSy.OpenTextFile(strPath, 1)
Do While Not objApriFile.AtEndofStream
sTesto = objApriFile.ReadLine
MioArray = Split (sTesto, " ")
redim strVar(ubound(MioArray))
FOR i=0 to UBound(MioArray)
strVar(i) = MioArray (i)
Response.Write "Numero variabile " & i & "...: " & strVar(i) & "
"
NEXT
SQL = " INSERT INTO TBLL ( CAMPOTESTO ) VALUES ('"& trim(pulisci(strVar(0))) &"' )"
Set RS = Conn.Execute(SQL)
response.write sql &"
"
Loop
objApriFile.close
Set objApriFile = Nothing
Set objFileSy = Nothing
%>
Il risultato è:
codice:
Numero variabile 0...: 338:
Numero variabile 1...: ATL
Numero variabile 2...: 14
Numero variabile 3...: Dic
Numero variabile 4...: 2005
Numero variabile 5...:
INSERT INTO TBLL ( CAMPOTESTO ) VALUES ( '338:' )
Ma perchè se cambio nella query il valore strVar, la query va in errore ????
:master: