473,769 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Not register double record in the DB MySQL

263 Contributor
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 2161
omerbutt
638 Contributor
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,Addre ss 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 Recognized Expert Contributor
Omerbutt, you should know to use the code tags by now! :-)

Dr B
Aug 22 '08 #3
omerbutt
638 Contributor
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 Recognized Expert Contributor
No problem Omer, that's what I thought!
Aug 22 '08 #5
viki1967
263 Contributor
many thanks omerbutt x your help; this script working. :)
regards
Aug 22 '08 #6
omerbutt
638 Contributor
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
3833
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 below. Logically I want to use max(version) as a constraint in a Where Clause. However, the max() function is not allowed directly in a where clause. I have contemplated a second table to track the max version for each file name. I would like...
0
1530
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 KEY (LayerID), UNIQUE KEY Fingerprint (Fingerprint), KEY IceTypeID (IceTypeID) ) TYPE=MyISAM;
12
2103
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 one date. Please help.
1
3694
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 (+, -, *, /) with DECIMAL columns are done with a precision of 64 decimal digits. Re: Floating Point limitations and using IEEE format floating point many numbers cannot be stored exactly in a FP format
6
14408
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
3655
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, and i wish to close html tag TD TR after ever three myqsl columns .the mysql record should be shown as bellow record 1 record 2 record 3 record 4 record 5 record 6 record 7 ...
1
4366
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 these new sets of codes have overwhelmed me a bit. Here's the new code: CREATE TABLE `users` ( `ID` int(11) NOT NULL auto_increment, `Username` varchar(255) NOT NULL, `Password` varchar(255) NOT NULL, `Temp_pass` varchar(55)...
0
1678
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 normal register. Shortly data of double register mysql. Please help. ( My english because of excuse me all )
1
3629
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. Ive got to get the mysql table to record the time in and time out and the ip address from which the person logged in or logged out each day. That is where the parse error is cropping up in file2 that i posted below. if...
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.