Ask a Question related to ASP Database, Design and Development.
-
Joost #1
insert CSV into access
Hi,
I use the following code to insert the data from my CSV into an access
database. But now I want the script to UPDATE the courses id they
already exist (so when the COURSENUMBER is known in the table),
otherwise he has to add just a new record.
How can I do this?
Thanks!
Joost
<%
'create instance of the Connection object
Set objRS = Server.CreateObject("ADODB.Recordset")
SQLstmt = "SELECT * FROM blaat"
objRS.Open SQLstmt, Conn , adOpenStatic , adLockOptimistic
'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
strURL = Server.MapPath("test.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, ";", 6)
objRS.AddNew
objRS("coursenumber") = arrText(0)
objRS("place") = arrText(1)
objRS("time") = arrText(2)
objRS("day1") = arrText(3)
objRS("day2") = arrText(4)
objRS("day3") = arrText(5)
objRS.Update
Loop
'close and destroy objects
objRS.Close
objFile.Close
Set objRS = nothing
Set Conn = nothing
Set objFile = Nothing
Set objFSO = Nothing
Response.Write("status ok")
%>
Joost Guest
-
INSERT Error from Access 97
I get the follow syntax error when trying to run the following SQL: INSERT INTO USERS (username, fullname, salt, password) VALUES ('stephen7',... -
Help with Flash insert to access
I am hoping someome can help me. I have a flash form that is to inderst to an Access database via an asp insert form. I had this survey... -
Need Utility to insert a CSV to ACCESS Table
Hi Guys, first of all thanks for your help. Can someone please help me find a ColdFusion component or custom tag which will allow me to import a... -
Insert to Access database error*** Please Help
When trying to insert into access database with a form created by the standard MX2004 Insert and form wizard, get the "Syntax " error as below. Line... -
access insert statement
have you tried? was there an error? I'm not sure that Access has the "@@identity".... I'd suggest trying and posting the specific errors. --... -
Aaron Bertrand - MVP #2
Re: insert CSV into access
> Set objRS = Server.CreateObject("ADODB.Recordset")
Stop doing this, for starters. Why do you need to select the entire table> SQLstmt = "SELECT * FROM blaat"
back to the ASP page, just to add rows?
Stop doing this, also. How about:> Do While Not objFile.AtEndOfStream
arrLines = split(objFile.ReadAll(), vbCrLf)
for i = 0 to ubound(arrLines)
arrText = split(arrLines(0), ";", 6)
...
next
Ugh. As you're going through the loop, assuming CourseNumber is, in fact, a> objRS.AddNew
> objRS("coursenumber") = arrText(0)
> objRS("place") = arrText(1)
> objRS("time") = arrText(2)
> objRS("day1") = arrText(3)
> objRS("day2") = arrText(4)
> objRS("day3") = arrText(5)
> objRS.Update
number:
sql = "SELECT courseNumber FROM blaat " & _
" WHERE courseNumber=" & arrText(0)
set rs = conn.execute(sql)
if rs.eof then
sql = "INSERT blaat(coursenumber, ...) " & _
"VALUES(" & courseNumber & ", ...)"
else
sql = "UPDATE blaat SET ... " & _
"WHERE courseNumber = " & arrText(0)
end if
conn.execute sql, , 129
Aaron Bertrand - MVP Guest



Reply With Quote

