Get ready for BLACK FRIDAY shopping starting in

Forums

ASP

This topic is locked

check if a value existst if not insert records

Posted 27 Feb 2005 15:35:32
1
has voted
27 Feb 2005 15:35:32 sander kerstens posted:
hi coders,

i want have a script which inserts a comma seperated document into the database
i want the script to check the emailadres against the database table if exists no insert if not
exist insert
the check script must be inside the loop because the comma seperated file contains more entries

the script inserting the csv works perfectly so no help on this just on the check if exist

this is the script:

'declare variables for the database
Dim objConn , objRS
'create instance of the Connection object
Set objRS = Server.CreateObject("ADODB.Recordset"
objRS.ActiveConnection = MM_braberconn_STRING
objRS.Source = "SELECT * FROM memberslist"
objRS.LockType = 2
objRS.Open ()
objRS_numRows = 0


'declare our variables for the file handling
Dim objFSO , strURL , objFile
'create an instance of the file system object
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
'this is the csv file downloaded from yahoo
strURL = Server.MapPath("/csv/import.csv"
'open the file
Set objFile = objFSO.OpenTextFile(strURL)
'while we are not at the end of the file
Do While Not objFile.AtEndOfStream
'store the contents of the file in strText
strText = objFile.readLine
'split the strText
arrText = split(strText, ",", 11)
if arrText(1)
objRS.AddNew
objRS("naam" = arrText(0)
objRS("bedrijfsnaam" = arrText(1)
objRS("straat" = arrText(2)
objRS("postcode" = arrText(3)
objRS("woonplaats" = arrText(4)
objRS("emailadres" = arrText(5)
objRS("telefoon" = arrText(6)
objRS("fax" = arrText(7)
objRS("gsm" = arrText(8)
objRS("website" = arrText(9)
objRS("catagorie" = arrText(10)
objRS.Update

Loop
'close and destroy objects
objRS.Close
objFile.Close
Set objRS = nothing
Set objFile = Nothing
Set objFSO = Nothing
%>

thanks in advance for your help

greetz Sander

Replies

Replied 04 Mar 2005 13:58:54
04 Mar 2005 13:58:54 Lee Diggins replied:
Hi Sander

I'm a little confused by exactly what you need, so Im just guessing here, this is just for the email field:

If objRS("emailadres" = "" Then
objRS("emailadres" = arrText(5)
End If

Post back with more info.

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>

Reply to this topic