473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Not register double record in the DB MySQL

263 100+
Not register double record in the DB MySQL

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
  1.  
  2. PercorsoCSV = "D:\Inetpub\wwwroot\CSV\file1.csv "
  3.  
  4.   Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  5.   strURL = percorsoCSV 
  6.  
  7.   Set objFile = objFSO.OpenTextFile(strURL)  
  8.   objFile.SkipLine()  
  9.  
  10.   strVariabile = ""
  11.   Do While Not objFile.AtEndOfStream
  12.  
  13.    strText = objFile.readLine   
  14.    arrText =  split(strText, ",", 17)
  15.  
  16. 'CHECK EXISTING ROWS IN THE DB MYSQL
  17. SQL = " SELECT * " 
  18. SQL = SQL & " FROM "  
  19. SQL = SQL & " tabellaCSV " 
  20. SQL = SQL & " WHERE "
  21. SQL = SQL & " NOME = '" & replace(arrText(0), """", "") & "' " 
  22. SQL = SQL & " AND "  
  23. SQL = SQL & " DATA = " & formatDBDate(replace(arrText(2), """", ""), "mysql") & " " 
  24. SQL = SQL & " AND "  
  25. SQL = SQL & " ORA = '" & replace(arrText(3), """", "") & "' "
  26. SQL = SQL & " AND " 
  27. SQL = SQL & " CODICE_PERSONALE = '" & replace(arrText(7), """", "") & "' "
  28. SQL = SQL & " AND " 
  29. SQL = SQL & " DESCRIZIONE = '" & replace(arrText(8), """", "") & "' "
  30. Set objRS = Server.CreateObject("ADODB.Recordset")
  31. objRS.open SQL, cn
  32.  
  33. 'CHECK objRS
  34. if objRS.eof then
  35.  
  36. 'CHECK THE SIMILAR ROWS
  37. if objRS("CODICE_PERSONALE") <> strVariabile  then
  38.  
  39. 'INSERT IN THE DB MYSQL
  40. strSql = "INSERT INTO tabellaCSV ... " 
  41. cn.execute(strSql)
  42.  
  43.   strVariabile = objRS("CODICE_PERSONALE")
  44.  
  45.  end if
  46.  
  47. else
  48.  
  49.   response.write "This record is already in the db!<br>"
  50.  
  51. end if
  52.   Loop
  53.  
  54.   objRS.Close()
  55.   Set objRS = Nothing 
  56.  
  57.   cn.Close()
  58.   Set cn = nothing
  59.  
  60. Set fsoMyFile = CreateObject("Scripting.FileSystemObject")
  61.  
  62. if fsoMyFile.FileExists (PercorsoCSV) then
  63.    fsoMyFile.DeleteFile PercorsoCSV
  64. end if
  65.  
  66. Set fsoMyFile = Nothing 
  67. Set objFSO = Nothing
  68.  
Aug 21 '08 #1
6 2128
omerbutt
638 512MB
hi viki1967
what i havent got so far is that if any record is inserted before, if that same record is inserted again you want to skip it or want it as an another separate entry , lets say i have a file in which i have these records
CSV file which hold ,Name,Dob,Address and Age
row1=Omer,19/10/1982,house No 23-b,25
row1=Omer,19/10/1982,house No 24-b,25
.................if i want that each these records should have a separate entry and the second row should not overwrite the first one then
Assume your connection is already running and you have set the recordset object and the the rows from the CSV file is save in the arraytext() array
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     strsql="SELECT * from table_name;"
  3.     recObj.open strsql, conn, 3
  4.         if rs.recordcount=0 then
  5.     response.Write("NO RECORDS TO MATCH TO , THIS IS THE FIRST REC")
  6.     else
  7.         Do until rs.EOF OR foundit
  8.             if(Strcomp(rs.fields("NAME"),arraytext(0),vbtextcompare)=0 && Strcomp(rs.fields("Dob"),arraytext(1),vbtextcompare)=0 && Strcomp(rs.fields("Address"),arraytext(2),vbtextcompare)=0 && Strcomp(rs.fields("Age"),arraytext(3),vbtextcompare)=0) then
  9.                 foundit=true
  10.             else
  11.                 rs.movenext
  12.             end if
  13.         Loop
  14.     end if    
  15. rs.close
  16. if if foundit=false then
  17.  strinert="insert ito table ......................"
  18. else
  19. endif
  20. %>
in this case you are checking all the fields in the row if all of them are the same then it will not enter record
hope you can do it your way from here
Aug 22 '08 #2
DrBunchman
979 Expert 512MB
Omerbutt, you should know to use the code tags by now! :-)

Dr B
Aug 22 '08 #3
omerbutt
638 512MB
Omerbutt, you should know to use the code tags by now! :-)

Dr B
:( SOWIE OR THAT JUST FORGOT :d
REGARDS,
OMER
Aug 22 '08 #4
DrBunchman
979 Expert 512MB
No problem Omer, that's what I thought!
Aug 22 '08 #5
viki1967
263 100+
many thanks omerbutt x your help; this script working. :)
regards
Aug 22 '08 #6
omerbutt
638 512MB
many thanks omerbutt x your help; this script working. :)
regards
:)
Good to hear that Viki,
regards,
omer
Sep 1 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tanamon | last post by:
Hello All, I am a MySQL newbie trying to write a query that selects file_name records possessing the highest numbered version for that unique file_name. I show sample data and two trial queries...
0
by: Phil Bitis | last post by:
CREATE TABLE tbllayer ( LayerID int(11) NOT NULL default '0', LayerSize int(11) NOT NULL default '0', IceTypeID int(11) NOT NULL default '0', Fingerprint char(16) binary default NULL, PRIMARY...
12
by: birdy | last post by:
Howe can i prevent a double entry in a database. Users can input their data into table. But how to prevent a double entry. Users can enter name and date So users can enter their names only on...
1
by: invinfo | last post by:
keywords: mysql accounting currency decimal fixed "floating point" Quoting the manual: DECIMAL)] If D is omitted, the default is 0. If M is omitted, the default is 10. All basic calculations...
6
by: sa_wahab | last post by:
Hi, 1. I want to calculate size of the record by mysql queries. Is it possible.. 2. What is the best way to calculate table record size which consists of Text type. Regards, @wahab.
11
khalidbaloch
by: khalidbaloch | last post by:
hi : all Friend i am a new member of this comunity as well in php myqsl i want learn that how to dispaly three or two record from a mysql table for example .. mysql table category has 21 columns,...
1
George Lft
by: George Lft | last post by:
ok, first of all, i built my register page using dreamweaver tool which the codes haven been out of control. Now i'm thinking that turning over everything - by using this another set of codes. And...
0
by: youngwe | last post by:
Professionals please to help. I have got problem. This; Data of the dynamic text, go to the php. Php is a data register mysql. But; data register double. This problem spring flash. Php to php data...
1
by: aajayaprakash | last post by:
Am so glad someone atleast wroteback ! I am trying to set up an attendance register where time someone comes into an office and leaves is recorded...a php based timecard/punchcard kind of thing. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.