I have developed a simple procedure asp to upload files csv and record data in the table mysql database.
This procedure not register double record because I have one control existing records in the table mysql database.
But if you reinsert the same file csv the rows first excluded are now registered.
For example I have this rows in the file csv:
row 1 = PIPPO, 25/07/2008, 11:50, XXXZZZ, YOU
row 2 = PIPPO, 26/07/2008, 01:50, XXXZZZ, YOU
row 3 = CAIO, 25/07/2008, 17:50, XXXYYY, NEWBIE
row 4 = TIZIO, 26/07/2008, 10:05, YYYZZZ, ADMIN
In first upload file csv in the db register the rows 1-3 and 4.
In second upload same file csv in the db register the row 2, eliminated in the first upload because similar to row 1.
This is my code ASP, can you help me?
Expand|Select|Wrap|Line Numbers
- PercorsoCSV = "D:\Inetpub\wwwroot\CSV\file1.csv "
- Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
- strURL = percorsoCSV
- Set objFile = objFSO.OpenTextFile(strURL)
- objFile.SkipLine()
- strVariabile = ""
- Do While Not objFile.AtEndOfStream
- strText = objFile.readLine
- arrText = split(strText, ",", 17)
- 'CHECK EXISTING ROWS IN THE DB MYSQL
- SQL = " SELECT * "
- SQL = SQL & " FROM "
- SQL = SQL & " tabellaCSV "
- SQL = SQL & " WHERE "
- SQL = SQL & " NOME = '" & replace(arrText(0), """", "") & "' "
- SQL = SQL & " AND "
- SQL = SQL & " DATA = " & formatDBDate(replace(arrText(2), """", ""), "mysql") & " "
- SQL = SQL & " AND "
- SQL = SQL & " ORA = '" & replace(arrText(3), """", "") & "' "
- SQL = SQL & " AND "
- SQL = SQL & " CODICE_PERSONALE = '" & replace(arrText(7), """", "") & "' "
- SQL = SQL & " AND "
- SQL = SQL & " DESCRIZIONE = '" & replace(arrText(8), """", "") & "' "
- Set objRS = Server.CreateObject("ADODB.Recordset")
- objRS.open SQL, cn
- 'CHECK objRS
- if objRS.eof then
- 'CHECK THE SIMILAR ROWS
- if objRS("CODICE_PERSONALE") <> strVariabile then
- 'INSERT IN THE DB MYSQL
- strSql = "INSERT INTO tabellaCSV ... "
- cn.execute(strSql)
- strVariabile = objRS("CODICE_PERSONALE")
- end if
- else
- response.write "This record is already in the db!<br>"
- end if
- Loop
- objRS.Close()
- Set objRS = Nothing
- cn.Close()
- Set cn = nothing
- Set fsoMyFile = CreateObject("Scripting.FileSystemObject")
- if fsoMyFile.FileExists (PercorsoCSV) then
- fsoMyFile.DeleteFile PercorsoCSV
- end if
- Set fsoMyFile = Nothing
- Set objFSO = Nothing