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? -
-
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
-
6 2161
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 - <%
-
strsql="SELECT * from table_name;"
-
recObj.open strsql, conn, 3
-
if rs.recordcount=0 then
-
response.Write("NO RECORDS TO MATCH TO , THIS IS THE FIRST REC")
-
else
-
Do until rs.EOF OR foundit
-
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
-
foundit=true
-
else
-
rs.movenext
-
end if
-
Loop
-
end if
-
rs.close
-
if if foundit=false then
-
strinert="insert ito table ......................"
-
else
-
endif
-
%>
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
Omerbutt, you should know to use the code tags by now! :-)
Dr B
Omerbutt, you should know to use the code tags by now! :-)
Dr B
:( SOWIE OR THAT JUST FORGOT :d
REGARDS,
OMER
No problem Omer, that's what I thought!
many thanks omerbutt x your help; this script working. :)
regards
many thanks omerbutt x your help; this script working. :)
regards
:)
Good to hear that Viki,
regards,
omer
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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;
|
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.
|
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
|
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.
| |
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 ...
|
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)...
|
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 )
|
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...
|
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...
|
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,...
| |
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,...
|
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...
|
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...
|
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...
|
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();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |